Skip to content

Instantly share code, notes, and snippets.

@sphingu
Created June 18, 2013 09:33
Show Gist options
  • Save sphingu/5803993 to your computer and use it in GitHub Desktop.
Save sphingu/5803993 to your computer and use it in GitHub Desktop.
How To See Validation Errors Details in MVC
// Get the Real error off the ModelState
var errors = GetRealErrors(ModelState);
private IEnumerable<ModelError> GetRealErrors(IEnumerable<KeyValuePair<string, ModelState>> modelStateDictionary)
{
var errorMessages = new List<ModelError>();
foreach (var keyValuePair in modelStateDictionary)
{
if (keyValuePair.Value.Errors.Count > 0)
{
errorMessages.AddRange(keyValuePair.Value.Errors.Where(error => !error.ErrorMessage.Contains("Info")));
}
}
return errorMessages;
}

How To See Validation Errors Details in MVC

  • While you are in debug mode within the catch {...} block open up the "QuickWatch" window (ctrl+alt+q) and paste in there:
  • This will allow you to drill down into the ValidationErrors tree. It's the easiest way I've found to get instant insight into these errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment