FormState.AddModelError at the form level with ASP.NET MVC 2 RC

In previous versions of ASP.NET MVC, you could use ModelState.AddModelError("**_FORM**", "error") to make a mistake at the form level, not the property level. This does not seem to work with the new ASP.NET MVC 2 RC anymore.

Is there any other way to do this? I am using <%= Html.ValidationSummary() %> in my View file ...

+6
c # asp.net-mvc
source share
2 answers

I personally use AddModelError("" - I don’t know where _FORM comes from? - and ValidationSummary() not black magic - instead I use my own helper, which, for example, includes specific (custom) exception messages in the output The helper is very easy to write β€” a simple foreach loop on ModelState β€” so you can think about writing your own, where you can show the form level, property level, or whatever you like.

+5
source share

the error is inside modelstate and sent to the validationsummary helper class with the following argument:

 this.ViewData.ModelState.Keys this.ViewData.ModelState.Values 
0
source share

All Articles