title: Dynamically disable a TextBoxFor if dropdown value changes to a certain value
body: <p>Is it possible to dynamically <code>disable</code> or make a TextBoxFor <code>readonly</code> if dropdown value changes to a certain value <strong>without using helpers or javascript</strong>? </p>
  
  <p><strong>Razor View</strong></p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(m =&gt; m.TypeId, new { @class = "col-md-2 control-label" })
      &lt;div class="col-md-4"&gt;
          @Html.DropDownListFor(m =&gt; m.TypeId, new SelectList(ViewBag.TypesDDL, "TypeId", "Name"), new { @class = "form-control" })
      &lt;/div&gt;
      @Html.LabelFor(m =&gt; m.TypeOthers, new { @class = "col-md-2 control-label" })
      &lt;div class="col-md-4"&gt;
      @if (Model.TypeId == "Others") {
          @Html.TextBoxFor(m =&gt; m.TypeOthers, new { @class = "form-control" })
          @Html.ValidationMessageFor(m =&gt; m.TypeOthers, "", new { @class = "text-danger" })
      }
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In the code above I used an if statement to display the <code>TypeOthers TextBoxFor</code> if the <code>TypeId DropDownListFor</code> is equals to <code>Others</code> but this doesn't work after load, If I change the dropdown value of <code>TypeId</code> to something that's not  <code>Others</code> the <code>TypeOthers TextBoxFor</code> doesn't appear.</p>
  
  <p>I know this can easily be done by using javascript just like in the code below but I want to know if this can be done just by using <code>razor</code>.</p>
  
  <pre><code>$("#TypeId").change(function () {
      if (document.getElementById("TypeId").value == "OTHERS") {
          document.getElementById("TypeOthers").disabled = false;
      } else {
          document.getElementById("TypeOthers").disabled = true;
      }
  });
  </code></pre>
  
  <p>If I'm not clear enough please just comment.</p>