I'm not sure if it is intended behavior or not but when I use a @Html.CheckBoxFor(x => x.CheckBox1)
it will output two input fields (one of which is false and one is true because html doesn't post back false checkboxes). But the actual html rendered is:
<input id="CheckBox1" name="CheckBox1" type="checkbox" value="true">
<input name="CheckBox1" type="hidden" value="false">
But when I use a @Html.HiddenFor(x => x.CheckBox2)
the output is:
<input id="CheckBox2" name="CheckBox2" type="hidden" value="True">
Note the 'true'
and the 'True'
. When the out of the box jquery.validate.js tries to use the equalTo function it will never be equal to each other because 'true' !== 'True'
.
To get around this I can modify the equalTo method to ignore case when comparing checkbox values but I was just curious if this is a bug with the MVC framework or this was intended behavior?
Here is a fiddle reproducing the issue (view source on the output to view the html): https://dotnetfiddle.net/LxOm3J
Edit 1: I have found in the CheckBoxFor source that it is passing a lower case 'true' when building the Checkbox. The question still remains, why lower case instead of proper case. https://www.symbolsource.org/Public/Metadata/NuGet/Project/Microsoft.AspNet.Mvc/4.0.20710.0/Release/.NETFramework,Version=v4.0/System.Web.Mvc/System.Web.Mvc/System.Web.Mvc/Html/InputExtensions.cs Line 96 of the source.