Created
June 27, 2018 10:06
-
-
Save csharpforevermore/974d6ed434ea7196f7580b9962e8ba71 to your computer and use it in GitHub Desktop.
MVC.NET - list out all the validation errors for a submitted form
This file contains hidden or 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
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