I'm developing and ASP.NET MVC app with C# and .NET Framework 4.7.
I want to 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 this if (isDisabled) disabled
doesn't work.
How can I add disabled
attribute conditionally?