Reputation: 73908
In my View in Razor I use a DroDownList I would like to have this control not Selectable. How to do it, (please post a sample)?
<div class="editor-field">
@Html.DropDownListFor(x => x.CandidateId, Model.CandidatesList)
</div>
Upvotes: 2
Views: 4317
Reputation: 87
You can try this:
@Html.DropDownListFor(
x => x.CandidateId,
Model.CandidatesList,
new { @disabled = "disabled" }
)
But you can not get the dropdown value in controller after submission. You can use a hidden field for setting the dropdown value.
Upvotes: 0
Reputation: 20037
You'd probably want to look at the override for DropDownListFor which take a dictionary of HTML attributes and perhaps pass something like 'disabled = "true"' through.
http://msdn.microsoft.com/en-us/library/ee703436(v=vs.108).aspx
<div class="editor-field">
@Html.DropDownListFor(x => x.CandidateId, Model.CandidatesList, new { disabled = "true" })
</div>
Upvotes: 2
Reputation: 37533
You use the disabled
attribute with values of true and false.
<div class="editor-field">
@Html.DropDownListFor(x => x.CandidateId, Model.CandidatesList, new { disabled = "true" })
</div>
Upvotes: 9
Reputation: 16144
@Html.DropDownListFor(x => x.CandidateId, Model.CandidatesList,
new { @disabled = "disabled" })
Upvotes: 1