Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created June 27, 2018 10:06
Show Gist options
  • Save csharpforevermore/974d6ed434ea7196f7580b9962e8ba71 to your computer and use it in GitHub Desktop.
Save csharpforevermore/974d6ed434ea7196f7580b9962e8ba71 to your computer and use it in GitHub Desktop.
MVC.NET - list out all the validation errors for a submitted form
public void Main(){
#if (!RELEASE && !PRODUCTION)
// this code is only called if we are compiling on a non-live configuration
GetLogErrors();
#endif
}
/// <summary>
/// Debug method to show what validation errors exist
/// </summary>
private void GetLogErrors()
{
var modelErrors = new List<string>();
foreach (var modelState in ModelState.Values)
{
foreach (var modelError in modelState.Errors)
{
modelErrors.Add(modelError.ErrorMessage);
}
}
modelErrors.Clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment