1

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

Richard77
  • 20,343
  • 46
  • 150
  • 252

2 Answers2

3

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
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 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 Dec 10 '09 at 18:13
0

It has meaning in MVC 2 as a way to specify a validation summary error, as described above.

But in MVC 3 and later, you need to pass an empty string as the key parameter to ModelState.AddModelError(). Passing "_FORM" to denote a validation summary error doesn't seem to work any longer.See this question for more details.

Community
  • 1
  • 1
Ivan Karajas
  • 1,081
  • 8
  • 14