Html.DropDownList - Disabled/Readonly
Regarding the catch 22:
If we use @disabled
, the field is not sent to the action (Mamoud)
And if we use @readonly
, the drop down bug still lets you change the value
Workaround: use @disabled
, and add the field hidden after the drop down:
@Html.HiddenFor(model => model.xxxxxxxx)
Then it is truly disabled, and sent to the to the action too.
Try this
Html.DropDownList("Types", Model.Types, new { @disabled = "disabled" })
<script type="text/javascript">
$(function () {
$(document) .ajaxStart(function () {
$("#dropdownID").attr("disabled", "disabled");
})
.ajaxStop(function () {
$("#dropdownID").removeAttr("disabled");
});
});
</script>