- 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.
Created
June 18, 2013 09:33
-
-
Save sphingu/5803993 to your computer and use it in GitHub Desktop.
How To See Validation Errors Details in MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment