asp.net mvc: why is Html.CheckBox generating an additional hidden input

If checkbox is not selected, form field is not submitted. That is why there is always false value in hidden field. If you leave checkbox unchecked, form will still have value from hidden field. That is how ASP.NET MVC handles checkbox values.

If you want to confirm that, place a checkbox on form not with Html.Hidden, but with <input type="checkbox" name="MyTestCheckboxValue"></input>. Leave checkbox unchecked, submit form and look at posted request values on server side. You’ll see that there is no checkbox value. If you had hidden field, it would contain MyTestCheckboxValue entry with false value.

Leave a Comment