6

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...

Greg B
  • 14,597
  • 18
  • 87
  • 141
Jeff Maes
  • 707
  • 8
  • 13

2 Answers2

5

I personally use AddModelError("" - I don't know where does _FORM come from? - and ValidationSummary() is no black magic - I use my own helper instead that, for example, includes specific (user-specific) exceptions messages into output. The helper is very easy to write - a simple foreach loop over ModelState - so you may consider writing your own one. There you're free to show form-level, property-level, or whatever you like.

Greg B
  • 14,597
  • 18
  • 87
  • 141
queen3
  • 15,333
  • 8
  • 64
  • 119
  • 3
    I did try AddModelError(null, ... but that didn't work. AddModelError("", ... is working like a charm! Thank you! – Jeff Maes Feb 09 '10 at 07:28
0

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
Greg B
  • 14,597
  • 18
  • 87
  • 141
Reza
  • 414
  • 2
  • 6
  • 18