0

I'm working on a Asp.net Razor application. I have a table on my page, and have some names of people as the y_axis for this table.

I have incorporated a tool tip (Tooltipster library) for these names. I would like to display information about these people in the tool tip, info such as their telephone number, city and ID.

This information lies in my database Model. I also have a ViewModel, to retrieve the information as well.

I was wondering how I would retrieve the information and place it in the title attribute that the names/y_axis is located (the information must go in the title for the tool tip to function correctly).

My script:

var engName = document.getElementsByClassName("dhx_matrix_scell");

for (var i = 0; i < engName.length; i++) {

    engName[i].className = engName[i].className + " tooltipss";
    engName[i].title = _______________________________
}

ViewModel:

 public class W6ViewModel
{
    public virtual ICollection<W6ENGINEERS> engineers { get; set; }
}

Controller for the index:

viewModel.engineers = db.W6ENGINEERS.OrderBy(w => w.Name).ToList();

What I tried so far, but get errors

var engName = document.getElementsByClassName("dhx_matrix_scell");
var name = engName.innerHTML();

for (var i = 0; i < engName.length; i++) {

    @{
        //get error here since name isn't visible to the Model
        var engineer = Model.engineers.Where(v => v.Name = name);
    }

    engName[i].className = engName[i].className + " tooltipss";
    engName[i].title = engineer.telephone;
}

Thanks for all your help in advance

5
  • Might help to post the markup related to dhx_matrix_scell
    – TGH
    Commented Jul 7, 2014 at 17:16
  • 2
    You could skip the javascript all together and just render the tooltips when the user loads the page. Just depends on how much load you expect from that.
    – jimSampica
    Commented Jul 7, 2014 at 17:22
  • If your model is being passed to your view, use razor to write those values. Why make extra trips to the server after rendering the page?
    – CM Kanode
    Commented Jul 7, 2014 at 17:22
  • 1
    You essentially have two options: Render them as part of the page and use JavaScript to make them visible, or fetch them via AJAX from another action when the tooltip becomes visible. Unless you're talking about a lot of data, there should be little difference between the two. The latter simply involves more requests to the server.
    – David
    Commented Jul 7, 2014 at 17:23
  • Thanks guys for the input. The markup related to the dhx_matrix_scell is created dynamically by another JavaScript function. unfortunately, I'm new to web development, and am unsure how to "render them as part of the page initially" Also view my edit please Commented Jul 7, 2014 at 17:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.