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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With