Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 MVC 3 中,是否有一种机制允许在返回结果视图之前枚举所有验证错误?
例如:
if (!ModelState.IsValid) { //Enumerate validation errors }
您可以遍历 ModelStateValues 集合
if (!ModelState.IsValid) { foreach (ModelState modelState in ModelState.Values) { foreach (ModelError error in modelState.Errors) { // error.ErrorMessage contains the error message } } }