asp.net mvc dropdownlist option disabled selected
Unfortunately not. There is no way to add attributes to a SelectListItem
, which is what gets rendered as an <option>
.
You would need to extend the SelectListItem
class, and then extend the DropDownListFor
to use it. It is unfortunately not very straightforward... It would have been nice for there to be an Attributes
dictionary on SelectListItem
for this purpose.
Here is an implementation of a custom attribute being applied:
Adding html class tag under <option> in Html.DropDownList