asp.net mvc - Razor ViewEngine HTML.Checkbox method creates a hidden input. Why? -


I've written the code below on my watch page;

  @ html.CheckBox ("ChxName", true)   

And I found the following result;

  & lt; Input checked "checked" id = "chxname" name = "chxName" type = "checkbox" value = "true" /> & Lt; Input name = "chxname" type = "hidden" value = "false" />   

Why is there an input element name with the check box?

Unchecked check boxes are not posted, so hidden fields (set as false ) Still allows model binding to work.

View the request. Back to the form on the form. If the checkbox is checked, you will see:

  Chaksnam = true & amp; ChxName = false   

uses the first binding model.

And, if the box is not checked, you will see:

  ChxName = false    

Comments