Please can someone help me, because I'm having real trouble getting on with validating my objects that have bound in my controller actions in one swoop.
I thought that IValidatableObject
s Validate()
method would fire every time the binding takes place, but this isn't true... if there is a general model error it won't fire.
This leads me to wonder, how am I supposed to perform a full complex validation on my object and return the full set of validation errors? No one wants to fix all of the reported errors on a web form, then submit it to have more returned to them.
I thought I might just be able to perform all of my validation in the Validate()
method, but this isn't true because seemingly there is no way of getting away from the general validation of models. For example if you were to attempt to bind a string
to an int
, it doesn't silently fail, it adds a model validation error and then doesn't fire Validate
to perform further validation on the object.
So I can't perform all of my validation just using one method:
- General model validation using validation attributes
- Reasons
- Can't perform advanced validation, such as conditional validation based on other values within the model
- It isn't designed to perform anything more than individual field validation
- Implement
IValidatableObject
and perform full validation inValidate()
method- Reasons
- There is no getting away or 'switching off' the general model validation so that it fails silently so that I can perform full validation on the object
- IValidatebleObject isn't always fired if general model validation fails in any way, such as a failed binding
How can I perform full validation of my object in one go, no matter whether the binding was successful or not?
Why doesn't IValidatableObject
fire the Validation()
method regardless of the binding success?