“_FORM”的含义是什么?在模型状态?
我正在浏览 AccountController 类(默认类)。我注意到“_FORM”在许多地方与 ModelState 一起使用。例如:
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.");
}
很容易说出用户名的含义(就像电子邮件、密码和确认密码一样)。但“_FORM”是什么?有什么特殊的含义吗?我没有看到它的定义在哪里。
感谢您的帮助
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您没有带有
name="_FORM"
的输入元素,则可以使用它来添加模型错误,该错误将显示在错误摘要中,但不会出现红色的输入。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.它在 MVC 2 中具有指定验证摘要错误的方式的含义,如上所述。
但在 MVC 3 及更高版本中,您需要将空字符串作为关键参数传递给 ModelState.AddModelError()。传递“_FORM”来表示验证摘要错误似乎不再有效。请参阅此问题了解更多详细信息。
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.