views:

75

answers:

1

I have an update action in a controller that performs an UpdateModel. Before I pass the data back to the view I want to log the properties that failed to validate.

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

+3  A: 

On Controller:

 foreach (ModelState state in ViewData.ModelState.Values)
        foreach (ModelError error in state.Errors)
          MyLog(error.ErrorMessage);
Andrey Tkach
@Andrey: thanks! this looks good... as soon as I can test it out I'll mark it as the answer.
Sailing Judo
Ok. For me it works. I'm using it in helper for localization of messages comming from validator.
Andrey Tkach