I’m really confused. I have the following html in a form:
<input class="check-box"
id="Data__Correct"
name="Data.Correct"
type="checkbox" value="Data.Correct" />
This creates the following on the web page
<input class="check-box"
id="Data__Correct"
name="Data.Correct"
type="checkbox" value="False" />
When I put a check in the checkbox, submit the form, and check with fiddler I see it’s sending:
Data.Correct False
I thought it should be the other way around. What’s happening?
You are misunderstanding how checkbox works. If the checkbox is unchecked then no value is passed to the backend. If the checkbox IS checked then the value in the
valueattribute is passed to the backend. In your case, you set value toFalse, so you are getting the stringFalsenot to be confused with the boolean value false.If your intent with
value='False'is to set the state of the checkbox on load, then you instead need to do this:Or
checked="checked"should also work I believe. If checked is present then the box is checked, otherwise it is unchecked.