我希望在Visual Studio中看到ModelState的所有错误,而无需编写任何代码,如:
foreach (ModelState modelState in ViewData.ModelState.Values) {
foreach (ModelError error in modelState.Errors) {
DoSomethingWith(error);
}
我正在找东西
ModelSate.Errors
感谢。
答案 0 :(得分:0)
如图所示制作一串错误:
foreach (ModelState modelState in ViewData.ModelState.Values) {
string desc = "";
foreach (ModelError error in modelState.Errors) {
desc = desc + " ," + error.ErrorMessage.ToString(); //here 'error.ErrorMessage' will have required error message
//DoSomethingWith(error.ErrorMessage.ToString());
}
}
如上所示' error.ErrorMessage' 会出现错误消息'错误' (仅限提问者使用&#39) ;错误'在问题中)。