tags:

views:

649

answers:

1

Hi

I want to get all the error messages out of the modelState without knowing the key values. Like I just want to do a for loop and and grab all the error messages that the ModelState has.

How can I do this?

Thanks

+9  A: 
foreach (ModelState modelState in ViewData.ModelState.Values) {
    foreach (ModelError error in modelState.Errors) {
        DoSomethingWith(error);
    }
}

See also http://stackoverflow.com/questions/573302/how-do-i-get-the-collection-of-model-state-errors-in-asp-net-mvc.

Oren Trutner