如何从ASP.Net MVC ModelState中所有的错误? [英] How to get all Errors from ASP.Net MVC modelState?
本文介绍了如何从ASP.Net MVC ModelState中所有的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要走出ModelState中的所有错误消息不知道键值。通过循环抓住所有的错误信息,该ModelState中包含的内容。
我怎样才能做到这一点?
解决方案
的foreach(ModelState中的ModelState在ViewData.ModelState.Values){
的foreach(在modelState.Errors ModelError错误){
DoSomethingWith(错误);
}
}
又见<一个href=\"http://stackoverflow.com/questions/573302/how-do-i-get-the-collection-of-model-state-errors-in-asp-net-mvc\">http://stackoverflow.com/questions/573302/how-do-i-get-the-collection-of-model-state-errors-in-asp-net-mvc.
I want to get all the error messages out of the modelState without knowing the key values. Looping through to grab all the error messages that the ModelState contains.
How can I do this?
解决方案
foreach (ModelState modelState in ViewData.ModelState.Values) {
foreach (ModelError error in modelState.Errors) {
DoSomethingWith(error);
}
}
这篇关于如何从ASP.Net MVC ModelState中所有的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文