jawad hasan
jawad hasan

Reputation: 115

How to disable DropDownList in MVC 3

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

Answers (5)

BizApps
BizApps

Reputation: 6130

Try this:

@Html.DropDownList("EquipID",null, "Select Equipment", new { @disabled = "disabled" })

Regards

Upvotes: 2

Sridhar Narasimhan
Sridhar Narasimhan

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

K D
K D

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

Daniel Liuzzi
Daniel Liuzzi

Reputation: 17147

@Html.DropDownList("EquipID", null, "Select Equipment", new { disabled = "disabled"})

Your list of equipments comes from ViewBag.EquipID.

Upvotes: 6

user2985029
user2985029

Reputation:

<div class="editor-field">
  @Html.DropDownList("EquipID", "Select Equipment", new { @disabled = "disabled" })
  @Html.ValidationMessageFor(model => model.EquipID)
</div>

Upvotes: 1

Related Questions