what would be the best method to override the validation of data in an mvc application

132 views Asked by At

I have a very large form I need the user to complete. They need to be able to save their progress whether valid or not. When they have come back at a later time, they can update and make valid - then submit the data.

I am using client side scripting (xval), server side attributes on the domain model.

2

There are 2 answers

2
Syd On

One option for you is to have a [Save Draft] button which would go to a different Action SaveDraft() instead of Save(). By having a separate method, you can decide on the amount of validation you want on the Save operation. That I think is cleaner.

To have the same Save action decide whether to apply the amount of validatation logic would be harder to read and maintain.

0
Giovanni Galbo On

I don't know much about xval, but maybe you can look into inheriting from xval attributes and doing the check there...

e.g. ConditionalRequiredAttribute : RequiredAttribute, which maybe can take the appropriate statuses to validate on.

Validation would be as simple as base.Validate() (or whatever it's called) on ConditionalRequiredAttribute's validate method if a validation condition is met (status != "Draft).

Since I don't know xval, I'm not sure how the client side validation works... does it create client side validation code? In this case, you'd have to write code that creates a similar wrapper in javascript (e.g. if(status != "Draft")... If validation simply makes an Ajax call to the server that returns a list of errors, then I imagine that you wouldn't have to do anything else.

Sorry I couldn't answer your question directly, but maybe this can help you come up with some ideas...