Get all model validation errors in ASP.NET MVC

In ASP.NET MVC you can get a list of all validation errors for your model from the ModelState:

  if (!ModelState.IsValid) {
    var modelErrors = new List<string>();
    foreach (var modelState in ModelState.Values) {
      foreach (var modelError in modelState.Errors) {
    // do something with the error list :)

Related posts:


comments powered by Disqus