Reputation: 15015
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?
Upvotes: 13
Views: 5266
Reputation: 22857
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
Upvotes: 18