I'm creating a select list by using the Html.DropDownListFor() helper in asp.net mvc. Does this helper class allow to disable this select list by default upon creation? e.g. output should look like:<select
disabled>
<option value="volvo">Volvo</option>
</select>
We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.
Yes, it is possible to change the enabled / disabled status of a DropDownList through a button. All you need to do is use the enabled property in the control and set it as true to enable and false to disable it.
To create a disabled drop down list you could try this:
@Html.DropDownListFor(
x => x.Value,
Model.Items,
new { disabled = "disabled" }
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With