C# – Html.CheckBoxFor() checked problem in ASP.Net MVC 2

asp.netasp.net-mvcc

It doesn't seem that the Html.CheckBoxFor helper adds the correct "checked" attribute when rendering the HTML.

I have a bool property rendered like so:

<%= Html.CheckBoxFor(m => m.Visible) %>

And the outputted HTML is this:

<input type="checkbox" value="true" name="Visible" id="Visible">

Is there some particular reason it does not add the "checked" attribute when the value is true?

Best Answer

This was a silly problem. I had forgot to add the bindings for my new Visible field and had only added it to my POCO class, therefore it was always false. Also, the value of the input tag was a red herring as it is always set to true, the actual value comes from a hidden field rendered right beneath the input tag like so:

<input type="hidden" value="false" name="Visible">