Wednesday, May 29, 2013

List all Model ModelState Errors MVC


List<string> errorsList = new List<string>();
foreach (ModelState modelState in ViewData.ModelState.Values)
{
          foreach (ModelError error in modelState.Errors)
         {
            errorsList.Add(error.ErrorMessage);
         }
}
foreach (var item in errorsList)
{
       ModelState.AddModelError("", item);
}
     

No comments:

Post a Comment