How to retrieve all the Errors from the ModelState in ASP.NET MVC ?

To display all the possible error messages from the ModelState in ASP.NET MVC , the developers would use the Html.ValidationSummary helper method in the View . How to get the list of all the Errors from the ModelState in ASP.NET MVC Controller ?

The ModelState.Values property is a ICollection which contains the list of all the states which the developers can use to filter out the error states as shown in the below sample code snippet.

How to retrieve all the Errors from the ModelState in ASP.NET MVC ?

public ActionResult Index()

{

var states = ModelState.Values;

// Error States

var errorsStates = from m in states

select m.Errors;

return View();

}