In my razor view, I use a drop down list. I want to have this control disabled (not selectable).
My code is:
<div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{ @disabled = "disabled" })</div>
But it doesn't work, my control is always enabled. Html page code is:
<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 dropdown conditionally, something like this:
<div class="field-list">@Html.DropDownListFor(model => model.LinguaCodiceMadre, Model.LinguaMadreList, new{@disabled=Model.IsDisabled ? "disabled" : "false"})</div>
but it doesn't work.
I tried both with
new{@disabled=Model.IsDisabled ? "disabled" : "false"}
and
new{disabled=Model.IsDisabled ? "disabled" : "false"}
but nothing, disabled attribute is not rendering on html page.
Anyone has an idea?
Model.LinguaMadreList
? – Norricode
public IEnumerable<SelectListItem> LinguaMadreList { get; set; } – Swigmodel.LinguaCodiceMadre
? – Norricode
[StringLength(10)] public string LinguaCodiceMadre { get; set; } – Swigdisabled
attribute is not rendering. – Gauldisabled
attribute?@Html.DropDownListFor(model => model.LinguaCodiceMadre,new SelectList(new []{"1","2"}),new {@disabled="disabled"})
– Gaul@Html.DropDownListFor(model => model.LinguaCodiceMadre,new SelectList(new []{"1","2"}),new {@disabled="disabled"})
, but it doesn't work. Html rendered is:<select id="LinguaCodiceMadre" name="LinguaCodiceMadre"> <option>1</option> <option>2</option> </select>
– Swig