views:

36

answers:

1

Hello,

I was going through the AccountController class (the default one). I noticed that "_FORM" is used at many places with the ModelState. For, isntance:

if (String.IsNullOrEmpty(userName))
        {
            ModelState.AddModelError("username", "You must specify a username.");
        }

if (!String.Equals(password, confirmPassword, StringComparison.Ordinal))
        {
            ModelState.AddModelError("_FORM", "The new password and confirmation password do not match.");
        }

It's easy to tell the meaning for the username (as it is for for email, password, and confirmpassword). but what's "_FORM"? Has it a special meaning? I did not see where it is defined.

Thank for helping

+2  A: 

If you don't have an input element with name="_FORM" this could be used to just add a model error which will be shown in the error summary but no inputs would appear in red.

Darin Dimitrov
It make sense. Thanks
Richard77
This is exactly right. The name "_FORM" is just a dummy so that it appears in the summary, but not in any field validation message. The MVC 2 templates use the empty string ("") instead of "_FORM", but the end result is the same.
Levi