Reputation: 115
I am using following markup on my view and Want to disable DropDownList
<div class="editor-field">
@Html.DropDownList("EquipID", "Select Equipment")
@Html.ValidationMessageFor(model => model.EquipID)
</div>
Upvotes: 1
Views: 6752
Reputation: 6130
Try this:
@Html.DropDownList("EquipID",null, "Select Equipment", new { @disabled = "disabled" })
Regards
Upvotes: 2
Reputation: 2653
We can pass the html attributes as arguments where we set any defined html attributes.
@Html.DropDownList("EquipID", "Select Equipment", new { @disabled = "disabled" })
Regards
Upvotes: 0
Reputation: 5989
If you correctly check the intelisence of the method you will get the attributes parameter which accept dictionary type. here you can pass one or more html attributes to customize your display according to your requirement.
for your solution you can add following
@Html.DropDownList("EquipID", null, "Select Equipment", new { disabled = "disabled"})
however if there are more attributes you need to customize/overwrite then you can easily do following
@Html.DropDownList("EquipID", null, "Select Equipment", new { disabled = "disabled", color="#ffffff", name="name"})
Upvotes: 0
Reputation: 17147
@Html.DropDownList("EquipID", null, "Select Equipment", new { disabled = "disabled"})
Your list of equipments comes from ViewBag.EquipID
.
Upvotes: 6
Reputation:
<div class="editor-field">
@Html.DropDownList("EquipID", "Select Equipment", new { @disabled = "disabled" })
@Html.ValidationMessageFor(model => model.EquipID)
</div>
Upvotes: 1