By default, @Html.DropDownListFor() is a convenient Razor helper to create a <select> tag containing <option> tags. But it is not possible to add custom attributes like “data-meow-xx=xxxx” to the option tags.
One solution is to create the <select> tag yourself:
1 2 3 4 5 6 7 8 9 10 |
<select name="@Html.NameFor(m => m.mycol)" id="@Html.IdFor(m => m.mycol)" class="form-control"> @foreach (var item in ViewBag.myoptions) { <option value="@item.name" data-src-mycustomstuff="myStuff/@item.name" selected="@(Model != null && item.name == Model.mycol)"> @item.name_friendly </option> } </select> |
Comments