In my razor mode, I use a drop-down list. I want this control to be disabled (not selectable).
My code is:
<div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{ @disabled = "disabled" })</div>
But this does not work, my control is always on. Html Page Code:
<select name="LinguaCodiceMadre" id="LinguaCodiceMadre" data-val-length-max="10" data-val-length="The field LinguaCodiceMadre must be a string with a maximum length of 10." data-val="true">
<option></option>
<option value="sq">Albanian</option>
<option value="de">German</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="it">Italian</option>
<option value="pt">Portuguese</option>
<option value="ru">Russian</option>
<option value="es">Spanish</option>
</select>
without the disabled attribute.
My real goal is to enable / disable the dropdown menu conditionally, something like this:
<div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{@disabled=Model.IsDisabled ? "disabled" : "false"})</div>
but that will not work.
I tried both with
new{@disabled=Model.IsDisabled ? "disabled" : "false"}
and
new{disabled=Model.IsDisabled ? "disabled" : "false"}
but nothing, the disabled attribute is not displayed on the html page.
Does anyone have an idea?
source
share