Within MVC 3, is there a mechanism that allows the enumeration of all validation errors before returning the resulting View?
For Example:
if (!ModelState.IsValid)
{
//Enumerate validation errors
}
You can loop through the ModelStateValues collection
if (!ModelState.IsValid)
{
foreach (ModelState modelState in ModelState.Values) {
foreach (ModelError error in modelState.Errors) {
// error.ErrorMessage contains the error message
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.