c# - How can I add disabled attribute conditionally? -
this question has answer here:
i'm developing , asp.net mvc app c# , .net framework 4.7.
i want add disabled attribute conditionally:
<div class="group"> @{bool isdisabled; } @if ((model.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid == "01") || (model.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid == "10")) { isdisabled = true; } else { isdisabled = false; } @html.dropdownlistfor( m => m.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid, new selectlist(model.variabledataitems, "id", "name", model.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid), new { @onchange = "onchangevariabledataid(this);", data_level_index = @levelindex, data_list_index = @vdataindex, if (isdisabled) disabled }) </div>
but if (isdisabled) disabled
doesn't work.
how can add disabled
attribute conditionally?
maybe can try :
@html.dropdownlistfor( m => m.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid, new selectlist(model.variabledataitems, "id", "name", model.variabledatalist[levelindex].variabledataforlevel[vdataindex].variabledataid), new { @onchange = "onchangevariabledataid(this);", data_level_index = @levelindex, data_list_index = @vdataindex, disabled = isdisabled ? "disabled" : "false" })
i haven't tested code plz let me know if it's correct.
Comments
Post a Comment