开发者

Partial Validation - ASP.NET MVC 2

开发者 https://www.devze.com 2023-03-03 12:39 出处:网络
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 usin

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消