Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 722
Oundless Avatar asked Feb 10 '10 17:02

Oundless


1 Answers

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

ViewData.ModelState.Values.Where( v => v.Errors.Count != 0 ).Count()
like image 172
tvanfosson Avatar answered Nov 10 '22 14:11

tvanfosson