title: Checkbox is checked but value not passed to controller in asp.net mvc
body: <p>I am developing application in ASP.Net MVC and getting strange problem. In my view I am showing checkbox as On/Off switch like this:</p>
  
  <p><img src="https://i.stack.imgur.com/PvXbW.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/LpZ28.png" alt="enter image description here"></p>
  
  <p>for this I am using following jquery code</p>
  
  <pre><code>function checkSwitch()
  {
    $('input.checkSwitch').each(function() {
  
      if($(this).attr('checked') == 'checked'){
          $(this).wrap('&lt;div class="checkSwitch on" /&gt;');
      } else {
          $(this).wrap('&lt;div class="checkSwitch off" /&gt;');
      }
  
      $(this).parent('div.checkSwitch').each(function() {
          $(this).append('&lt;div class="checkSwitchInner"&gt;&lt;div class="checkSwitchOn"&gt;On&lt;/div&gt;&lt;div class="checkSwitchHandle"&gt;&lt;/div&gt;&lt;div class="checkSwitchOff"&gt;Off&lt;/div&gt;&lt;/div&gt;');
      });
  
    });
  }
  
  $(document).on('click', 'div.checkSwitch', function() {
  
  var $this = $(this);
  
  if($this.hasClass('off')){
      $this.addClass('on');
      $this.removeClass('off');
      $this.children('input.checkSwitch').attr('checked', 'checked');
  } else if($this.hasClass('on')){
      $this.addClass('off');
      $this.removeClass('on');
      $this.children('input.checkSwitch').removeAttr('checked');
  }
  
  });
  </code></pre>
  
  <p>Html code for showing checkbox in view is like this:</p>
  
  <pre><code>&lt;script&gt;
     checkSwitch();
  &lt;/script&gt;
  @Html.CheckBoxFor(model =&gt; model.ENABLED, new { @class = "checkSwitch", @checked = "checked" })
  </code></pre>
  
  <p>here ENABLED is boolean field in model like this:</p>
  
  <pre><code>public bool ENABLED { get; set; }
  </code></pre>
  
  <p>In browser for this view html code generated is like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Q6Qbl.png" alt="enter image description here"></p>
  
  <p>Now when I open view, checkbox is displayed as On/Off switch, when I make checkbox which is On(checked) to Off(unchecked) OR Off(unchecked) to On(checked) (ie. click only ONCE) and submit form it post proper values to controller. But when I click more than ONCE to change checkbox status like On(checked) to Off(unchecked) again to On(checked) OR click any number of times and at end make it On(checked) it posts false to controller everytime. I don't know why this is happening. As per jquery code above it's making checkbox checked when it's On(checked). I cross-chekced it's working in FireBug it's added attribute Checked="Checked" when checkbox is checked(On) and removes attribute when it's unchecked(Off). I am not able to find out reason why it's not posting true even checkbox is checked(On) when it's clicked more than ONCE. Please tell me what's wrong in code.</p>
  
  <p>Thanks...</p>