简体   繁体   中英

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. This seems not to work anymore with the new RC of ASP.NET MVC 2.

Is there another way how to do it? I use <%= Html.ValidationSummary() %> at my View-file...

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

the error are inside modelstate and is send to the helper class of validationsummary by following argument:

this.ViewData.ModelState.Keys

this.ViewData.ModelState.Values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM