Partial Validation - ASP.NET MVC 2
I am doing both client and server side validation and for one 开发者_StackOverflow中文版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?
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.
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/
精彩评论