if (!ModelState.IsValid)
{
List<string> Keys = ModelState.Keys.ToList();
//获取每一个key对应的ModelStateDictionary
string msg = string.Empty;
foreach (var key in Keys)
{
var errors = ModelState[key].Errors.ToList();
//将错误描述添加到Allkey中
foreach (var error in errors)
{
msg = msg + error.ErrorMessage + “</br>”;
}
}
ViewBag.DataErrorMessage = msg;
return View(register);
}