title: Enabling/Disabling MVC controls with jQuery
body: <p>I've got a table with multiple editable fields that correspond to an MVC model object. Currently, I've got a cell in each row with two buttons that will toggle between an edit/save function when they are clicked. I've got the buttons working now to where it will switch between the two buttons so that only one is visible at a time.</p>
  
  <p><strong>The Problem:</strong></p>
  
  <p>Currently, I'm setting a disabled property in Razor that successfully grays out the controls when they are not in 'edit' mode.</p>
  
  <pre><code>&lt;table&gt;
       &lt;thead&gt;
            ...stuff here
       &lt;/thead&gt;
       &lt;tbody&gt;
  @foreach(var item in Model)
  {
    &lt;tr&gt;
       ...some columns
       &lt;td class="selectDropDown"&gt;
            @Html.DropDownListFor(x =&gt; item.Prop1, (SelectList)ViewBag.Prop1Options, item.Prop1, new { @class = "form-control", @disabled=true })
       &lt;/td&gt;
       &lt;td class="editableTxt"&gt;
            @Html.TextBoxFor(x =&gt; item.Prop2, new { @class = "form-control", @disabled = "true"})
       &lt;/td&gt;
       &lt;td class="checkBox"&gt;
          @Html.CheckBoxFor(x =&gt; item.Prop3, new { @class = "checkbox", @disabled = "true" })
            ...Other Columns
        &lt;td class="buttons"&gt;
           &lt;btn class="btn btn-sm btn-primary editBtn"&gt;&lt;i class="glyphicon glyphicon-edit"&gt;&lt;/i&gt;&lt;/btn&gt;
           &lt;btn class="btn btn-sm btn-success saveBtn" style="display:none"&gt;&lt;i class="glyphicon glyphicon-floppy-disk"&gt;&lt;/i&gt;&lt;/btn&gt;
         &lt;/td&gt;
        &lt;/tr&gt;
  }
     &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>So now in jQuery, I've got two handlers which should simply do the following when clicked:</p>
  
  <ol>
  <li>Hide the button not currently in use</li>
  <li>Display the other function button</li>
  <li>Enable/Disable the editable fields.</li>
  </ol>
  
  <p>Here is the code:</p>
  
  <pre><code> $(document).on('click', '.editBtn', function () {
  
  
      var editButton = $(this);
      var selectedRow = $(this).parent();
  
      selectDropDown = selectedRow.closest('tr').children('td.selectDropDown');
      editableText = selectedRow.closest('tr').children('td.editableTxt');
      checkBox = selectedRow.closest('tr').children('td.checkBox');
  
  
      selectDropDown.prop('disabled', false);
      editableText.prop('disabled', false);
      checkBox.prop('disabled', false);
  
      editButton.hide();
      selectedRow.find('.saveBtn').show();
  });
  </code></pre>
  
  <p>One of these functions exists for both buttons and they are successful at showing/hiding the buttons but the properties are not enabling/disabling on click as I'm expecting them to.</p>
  
  <p>I have tried using <code>$().attr()</code> and <code>$().removeAttr()</code> for this as well. Additionally, I have changed the disabled property to <code>'disabled'</code>, instead of the current Boolean value with no luck. Is there some reason this would not work in MVC? Is there something going on in the background with my functions that would prevent the modification of the HTML properties?</p>
  
  <p><strong>EDIT:</strong> Should also note that:</p>
  
  <pre><code>selectDropDown = selectedRow.closest('tr').children('td.selectDropDown');
  </code></pre>
  
  <p>returns the following html:</p>
  
  <pre><code>&lt;select class="form-control" disabled="true" id="item_Prop" name="item.Prop"&gt;&lt;option value=""&gt;Value&lt;/option&gt;
      &lt;option&gt;Value&lt;/option&gt;
      &lt;option&gt;Value&lt;/option&gt;
      &lt;option&gt;Value&lt;/option&gt;
      &lt;option&gt;Value&lt;/option&gt;
      &lt;option&gt;Value&lt;/option&gt;
      &lt;/select&gt;
  </code></pre>