Get all ModelState Errors on view

asp.net-mvc-3, c#, html

Solution

You can access it through `ViewData.ModelState`. If you need more control with errors on your view you can use

`ViewData.ModelState.IsValidField("name_of_input")`

or get a list of inputs with errors like this:

var errors = ViewData.ModelState.Where(n => n.Value.Errors.Count > 0).ToList();

Problem

At my Controller I add some ModelState Errors. So, when I render my View, I want to get all these Errors and change the color of the labels of the fields that contain a error. So, I think I need to get all the ModelState Errors, get the field names and then change the color. This is the a good way? How can I get the ModelState Errors in my view?

Original source

Related problems