Tutorial :ASP.NET MVC Newbie - Default Login Page Remember Me Checkbox


When you start an ASP.NET MVC project in Visual Studio 2008, you get a fully loaded site template, including login forms and the like. In the default form to login, you will find this in the markup...

<%= Html.CheckBox("rememberMe") %>  

When you view the source in the browser, you will see that this renders to...

<input id="rememberMe" name="rememberMe" type="checkbox" value="true" />  <input name="rememberMe" type="hidden" value="false" />  

What is the purpose of this hidden field, and the default values? Is there a reason for this? Makes no sense to me.


This is the comment from the ASP.NET MVC source:

// Render an additional <input type="hidden".../> for checkboxes. This  // addresses scenarios where unchecked checkboxes are not sent in the request.  // Sending a hidden input makes it possible to know that the checkbox was present  // on the page when the request was submitted.  

In short: unchecked checkboxes (values) are not sent in the request. If the checkbox is unchecked then the value from the hidden input will be send in the request.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »