Why does the checkbox also contain a hidden tag?

Possible duplicate:
asp.net mvc: why does Html.CheckBox generate additional hidden input

I show a checkbox in an asp.net mpc application, and the control also displays a hidden field as follows:

<input id="blah-64" name="blah-64" value="true" type="checkbox">
<input name="blah-64" value="false" type="hidden">

The problem is that when I submit the form, the bla-64 form key is turned off.

Why is this?

+3
source share
1 answer

If you look at the source code for the checkbox helper, you will see a comment that explains it. It looks like this:

if (inputType == InputType.CheckBox) { 
    // Render an additional <input type="hidden".../> for checkboxes. This 
    // addresses scenarios where unchecked checkboxes are not sent in the request. 
    // Sending a hidden input makes it possible to know that the checkbox was present 
    // on the page when the request was submitted. 
...

, W3C , : " , "on" ". ( ). , , . , HTML .

+8

Source: https://habr.com/ru/post/1783485/


All Articles