December 08, 2014
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) {
modelErrors.Add(modelError.ErrorMessage);
}
}
// do something with the error list :)
}
Comments
comments powered by Disqus