Razor ViewEngine HTML.Checkbox method creates a hidden input. Why? [duplicate]

Unchecked checkboxes are not posted, so the hidden field (set as false) allows the model binding to still work.

Look at Request.Form on the post back. If the checkbox is checked, you’ll see:

ChxName=true&ChxName=false

The model binder uses the first value.

and, if the box isn’t checked, you’ll see:

ChxName=false

Leave a Comment