Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc checkbox inconsistency
    text
    copied!<p>I'm using an checkbox on an ASP.NET MVC form like so:</p> <pre><code>&lt;%=Html.CheckBox("AgreeToRules", Model.AgreeToRules)%&gt; </code></pre> <p>The AgreeToRules property on the model is a boolean value. During testing, this all worked fine. However, now that we've gone live with this app, I'm seeing a relatively small but significant number of errors with the following messaging:</p> <blockquote> <p>System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Boolean' failed. See the inner exception for more information. ---> System.FormatException: Y is not a valid value for Boolean. ---> System.FormatException: String was not recognized as a valid Boolean.</p> </blockquote> <p>This appears to happen when the view engine tries to render the form after a post, and the value of the checkbox that is returned from the ValueProvider looks like:</p> <blockquote> <p>Y,false</p> </blockquote> <p>OR</p> <blockquote> <p>N,false</p> </blockquote> <p>The html that is rendered in the original form looks like:</p> <pre><code>&lt;input id="AgreeToRules" name="AgreeToRules" type="checkbox" value="true" /&gt; &lt;input name="AgreeToRules" type="hidden" value="false" /&gt; </code></pre> <p>During testing, I expected (and showed) the posted value to look like:</p> <blockquote> <p>true,false</p> </blockquote> <p>if checked or </p> <blockquote> <p>false</p> </blockquote> <p>if not checked. So where is the N and Y coming from?</p> <p>I added user agent to the list of information returned from the error handler and it appears (so far) that all of the errors are occuring under windows XP with FF 3.0.10, but that's exactly what I have tested with and the problem did not exist during testing. </p> <p>Any thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload