简体   繁体   English

ASP.NET MVC 2 RC在表单级别上的ModelState.AddModelError

[英]ModelState.AddModelError on form level with ASP.NET MVC 2 RC

In the previous versions on ASP.NET MVC, you could use ModelState.AddModelError("**_FORM**", "error") to make an error on the form-level instead of a property-level. 在ASP.NET MVC的ModelState.AddModelError("**_FORM**", "error")版本中,您可以使用ModelState.AddModelError("**_FORM**", "error")在表单级别而不是属性级别上发生错误。 This seems not to work anymore with the new RC of ASP.NET MVC 2. 这似乎不再适用于ASP.NET MVC 2的新RC。

Is there another way how to do it? 还有另外一种方法吗? I use <%= Html.ValidationSummary() %> at my View-file... 我在我的View文件中使用<%= Html.ValidationSummary() %> ...

我个人使用AddModelError("" - 我不知道_FORM来自哪里? - 并且ValidationSummary()不是黑魔法 - 我使用自己的帮助器,例如,包括特定的(用户特定的)异常消息帮助器很容易编写 - 一个简单的foreach循环遍历ModelState - 所以你可以考虑编写自己的一个。你可以自由地显示表单级别,属性级别或任何你喜欢的东西。

the error are inside modelstate and is send to the helper class of validationsummary by following argument: 错误在modelstate中,并通过以下参数发送到validationsummary的helper类:

this.ViewData.ModelState.Keys

this.ViewData.ModelState.Values

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC中ModelState.AddModelError中的关键参数有什么意义? - What is the point of the key parameter in ModelState.AddModelError in ASP.NET MVC? Asp.Net Core Razore Pages 中的“ModelState.AddModelError”显示不正确的错误消息 - Incorrect error message is displayed by "ModelState.AddModelError" in Asp.Net Core Razore Pages ModelState.AddModelError 在 asp.net.core RAZOR 页面中不显示任何消息 - ModelState.AddModelError doesn't show any message in asp.net.core RAZOR pages 添加ModelState.AddModelError而无需重新加载页面(mvc4) - Add ModelState.AddModelError without reload the page (mvc4) 当MVC4中的模型为空时如何显示ModelState.AddModelError - How to show ModelState.AddModelError when the Model is Empty in MVC4 未在PartialView中显示Modelstate.addmodelerror - Modelstate.addmodelerror not showing in PartialView 创建一个类型化的ModelState.AddModelError() - Creating a typed ModelState.AddModelError() 通过javascript提交表单后将ModelState.AddModelError添加到视图中 - Add ModelState.AddModelError to the view after submitting form through javascript 更改 ModelState.AddModelError 消息的字体颜色 - Changing the FONT color of the ModelState.AddModelError message ASP.NET MVC - ModelState 无效但可以访问表单内容 - ASP.NET MVC - ModelState is invalid but form content is acessible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM