Search code examples
c#asp.netasp.net-mvcrazorvalidationsummary

How do I find out the error count in a ASP.NET MVC View?


I want to format the title of my Validation Summary using a string something like:

"There are {0} errors on this page."

How do I find out the number of errors without doing it in the controller and adding it to View Data?


Solution

  • I assume you mean from the view. The following is untested.

    ViewData.ModelState.Values.Where( v => v.Errors.Count != 0 ).Count()