參考:http://www.cnblogs.com/darrenji/p/4415887.html
if (ModelState.IsValid)
{
....
}else{
String Message = "";
var errors = ModelState.Where(m => m.Value.Errors.Any())
.Select(x => x.Value.Errors);
foreach (var item in errors)
{
var fieldErrors = item.Select(e => e.ErrorMessage).FirstOrDefault();
Message += fieldErrors;
}
}
留言
張貼留言