title: How can I add disabled attribute conditionally?
body: <p>I'm developing and ASP.NET MVC app with C# and .NET Framework 4.7.</p>
  
  <p>I want to add disabled attribute conditionally:</p>
  
  <pre><code>&lt;div class="group"&gt;
      @{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 =&gt; 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
          })
  &lt;/div&gt;
  </code></pre>
  
  <p>But this <code>if (isDisabled) disabled</code> doesn't work.</p>
  
  <p>How can I add <code>disabled</code> attribute conditionally?</p>