[英]Enumerate list of MVC Model validation errors in code-behind
Within MVC 3, is there a mechanism that allows the enumeration of all validation errors before returning the resulting View? 在MVC 3中,是否有一种机制允许在返回结果View之前枚举所有验证错误?
For Example: 例如:
if (!ModelState.IsValid)
{
//Enumerate validation errors
}
You can loop through the ModelStateValues collection 您可以遍历ModelStateValues集合
if (!ModelState.IsValid)
{
foreach (ModelState modelState in ModelState.Values) {
foreach (ModelError error in modelState.Errors) {
// error.ErrorMessage contains the error message
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.