How can I pass back the validation errors I find when using DbEntityValidationException
try
{
db.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
this.ModelState.AddModelError(validationError.PropertyName,
validationError.ErrorMessage);
}
}
return RedirectToAction("AccessDetail", "Home", new { IDValue = access.ID });
}
It appears that when I do this RedirectToAction
my ModelState
refreshes and I can not view the errors it found.
The AccessDetail populates a view model that has many different sources of data in it. So passing just the access to the View does not work.
I was looking at this question but it didn't fit my needs as my view is populated with a ViewModel