How can I see the validation results during controller action?

I have an update action in a controller that does an UpdateModel. Before passing data back to the view, I want to register the properties that could not be checked.

I expected the dictionary that the errors are stored in is in ModelState (since the AddModelError () method exists), but that doesn't seem to be the case. How can I access this dictionary while in the controller?

+1


a source to share


1 answer


On Controller:



 foreach (ModelState state in ViewData.ModelState.Values)
        foreach (ModelError error in state.Errors)
          MyLog(error.ErrorMessage);

      

+4


a source







All Articles