So the first thing you should do it take a look at the actual data being sent to the server with chrome debug tools or similar. What you might find is that your checkbox value will be set to on if checked, or it will be missing completely if un-checked.
One suggestion in the comments was @Html.CheckBoxFor, but this also suffers the fact that nothing will be sent if the checkbox is un-checked and in specific situations that can still become a problem.
You have two solutions - fix it on the client, or fix it on the server.
Fix it on the client:
To do this, you'll need to (with javascript) add a hidden field for every checkbox. Forgive me, I'm not by an editor to test it out but it might look something like this (from memory):
$('input[type="checkbox"]').each(function(el) {
var hidden = $('<input type="hidden" />');
hidden.name = el.name;
el.after(hidden);
el.on("change", function(el) {
hidden.value = el.checked ? "true" : "false";
});
});
Fix it on the server:
To do this, you'll need to create a custom PropertyBinder which recognizes on as a boolean true. This would be set on a property-attribute level. You could alternatively override the global ModelBinder to do this so you don't need to specifically annotate a property for this to work.
Personally, I prefer the "fix it on the client" method, because you will get either true or false posted back to the server every time which is what you'd expect and is the closest to the way that HtmlHelper does it.
Html.CheckBoxForinstead of using manual HTML.value="false"so all it can ever submit isfalse. And if you not gong to use theHtmlHelpermethods, then don't bother using mvc since you will never get correct model binding.value="false"it was one of my testings, would you be able to explain more what you mean by: And if you not gong to use the HtmlHelper methods, then don't bother using mvc since you will never get correct model binding. It's very important for me to fully understand what you mean. Thanks!HtmlHelperis naive.