views:

662

answers:

1

I'm using MVC2 with data annotations for validation on my page. I require a name and a valid birth date to be present. I'm providing both, and I break into the date validator to ensure that the birth date is valid (and it is), but for some reason Model.IsValid is false in my post action. I'm not seeing anything in my ValidationSummary.

How can I find out what is invalid in the ModelState?

+3  A: 

You need to iterate through the ModelState collection checking the ModelState.Errors collection count for each property is greater than 0. To get the collection of modelstate items in error, something like

ModelState["Property"].Where(ms => ms.Errors.Count > 0)

Kindness,

Dan

Daniel Elliott
Add a breakpoint in your controller action and then dig into the Errors collection to track down the exact field (or fields) its having a problem with.
Nathan Taylor
Thank you. I was looking for a strongly typed error collection. I've found the error I was looking for.
Mike Pateras