Question

I want to create Html helper method to add title html attribute for each items in DropDownListFor control.

 @Html.DropDownListFor(m=> m.StateId, Model.States)

 public class Model
 {
    public int? StateId {get; set;}
    public List<SelectListItem> States {get; set;}
 }

 In controller,
  Model m = new Model();
  m.States = GetStates(). This will return List<SelectListItem> of States with Value and Text.

Now I want to create html helper method to add title attribute for each item with text value.

Was it helpful?

Solution

You will need to create on your own.

You can pull from similar implementation Adding html class tag under <option> in Html.DropDownList

Also give a try to

@Html.DropDownListFor(model => model.priority, new SelectList(ViewBag.Priority, "Value", "Text"), "-- Select Priority --", new { @class = "required", title="priority" })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top