ModelState plays an important role in client-side validation with ASP.NET MVC. Today I wanted to validate my model on server side and prepare a list of errors based on this validation.
I was able to do this using a little LINQ,
public static List<string> GetErrorListFromModelState(ModelStateDictionary modelState)
var query = from state in modelState.Values
from error in state.Errors
var errorList = query.ToList();
The above method returns a list of validation errors. Hope this helps :)
Further Reading :