List<string> sb = new List<string>();
//获取所有错误的Key
List<string> Keys = ModelState.Keys.ToList();
//获取每一个key对应的ModelStateDictionary
foreach (var key in Keys)
{
var errors = ModelState[key].Errors.ToList();
//将错误描述添加到sb中
foreach (var error in errors)
{
sb.Add(key.ToString() + ":" + error.ErrorMessage);
}
}
原文地址:https://www.cnblogs.com/hanshuhe/p/8926079.html
时间: 2024-10-12 00:00:19