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.

Était-ce utile?

La 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" })
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top