• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1482
  • Last Modified:

C# Adding title attribute to SelectListItem

This code is from a MVC4 project using Razor. No Razor shown here though.

var serverListModel = new ServerList();
var dismissedList = from String[] v in ldbh.getAllDismissedServers() orderby v[1] select v;
foreach (String[] v in dismissedList) {
    String title = "Stop date: " + v[2] + " End date: " + v[3];
    serverListModel.DropDownItemsDismissedNodes.Add(new SelectListItem { Text = v[1], Value = v[0] });

Open in new window

SelectListItem only accepts Text, Value and Selected. What if I want to add an attribute Title? I can do that with jQuery if I wanted and see it work, but I would prefer it done from the server side.
1 Solution
käµfm³d 👽Commented:
SelectListItems get translated into <option> elements of a <select> upon rendering. <option> elements don't contain title attributes, which is why you don't have anything available to you on the server side. If you are setting a title for the purpose of having a tooltip, then I don't believe this functionality will work cross-browser, and that Javascript will be your only recourse.
itniflAuthor Commented:
I used jQuery and Javascript to get things done. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now