1

I am doing both client and server side validation and for one particular View I need to validate a field that isn't posted in the other views. How can I do this if I'm using the same model for both?

3
  • 1
    Can you show some code for the model? Commented May 8, 2011 at 5:32
  • You can do specific client-side validation on the new view, but on the server side I think you're going to need a bit of view-specific code to perform the validation on the other field, if you're using the same ViewModel. I don't know of anything "out of the box" that fulfills the concept of "view-specific validation." Commented May 8, 2011 at 17:03
  • Thanks Robert. Would that view specific validation basically be implemented by directly generating an error message for the View versus use of validation methods? Commented May 8, 2011 at 18:40

2 Answers 2

1

If one view models isn't suitable for both views then you should have two view models.

To stay DRY (Don't repeat yourself) you can inherit one view model from the other and add the additional property.

Sign up to request clarification or add additional context in comments.

Comments

0

FluentValidation is perfect for this scenario. You can write two different validator classes and invoke them depending on your context. Check out their CodePlex site below:

http://fluentvalidation.codeplex.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.