如何从 ASP.Net MVC modelState 获取所有错误? [英] How to get all Errors from ASP.Net MVC modelState?

查看:38
本文介绍了如何从 ASP.Net MVC modelState 获取所有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不知道键值的情况下从 modelState 中获取所有错误消息.循环获取 ModelState 包含的所有错误消息.

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.

我该怎么做?

推荐答案

foreach (ModelState modelState in ViewData.ModelState.Values) {
    foreach (ModelError error in modelState.Errors) {
        DoSomethingWith(error);
    }
}

另见 如何获取 ASP.NET MVC 中模型状态错误的集合?.

这篇关于如何从 ASP.Net MVC modelState 获取所有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆