Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled select list with Html.DropDownListFor helper

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>

like image 401
kmb Avatar asked Mar 11 '11 22:03

kmb


People also ask

How to disable dropdown list in Html?

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.

How disable HTML dropdown in MVC?

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.


1 Answers

To create a disabled drop down list you could try this:

@Html.DropDownListFor(
    x => x.Value,
    Model.Items,
    new { disabled = "disabled" }
)
like image 166
Darin Dimitrov Avatar answered Nov 15 '22 20:11

Darin Dimitrov