[英]Choose the best Client/Server Validation Framework for MVC
Im trying to choose the best server/client validation framework to use with my MVC application. 我试图选择最好的服务器/客户端验证框架来与我的MVC应用程序一起使用。 I would like to know what is the best validation framework to use with MVC to do server/client validation.
我想知道与MVC一起用于服务器/客户端验证的最佳验证框架是什么。
My options are: 我的选择是:
With the upcoming MVC 2, it looks like MS is leaning towards the System.ComponentModel.DataAnnotations
library. 在即将发布的MVC 2中,MS似乎倾向于使用
System.ComponentModel.DataAnnotations
库。 It's pretty nice - does a lot of code generation for you. 非常好-为您完成了很多代码生成。
I've been using xVal with great success. 我一直在使用xVal取得巨大成功。
The best thing is you can fully automate validation: 最好的事情是您可以完全自动化验证:
DataAnnotations
(or special rules) to your business layer POCO classes (if you have them) or entity classes' metadata buddy classes if you use entities up to controller layer DataAnnotations
(或特殊规则)放入您的业务层POCO类(如果有)或实体类的元数据伙伴类(如果您使用的是直到控制器层的实体) Validate()
method, filter calls this method and fills ModelState.Errors
when validation fails. Validate()
方法的特定接口,filter调用此方法并在验证失败时填充ModelState.Errors
。 if (ModelState.IsValid) { ... }
in your controller action that needs to work differently when model isn't valid if (ModelState.IsValid) { ... }
This way you've set up automatic object validation. 这样,您可以设置自动对象验证。 All your controller actions will do is check Model validity.
您的控制器所有动作将是检查模型有效性。
Asp.net MVC 2 will have something very similar to xVal already built in the framework so it's up to you which version are you using. Asp.net MVC 2具有与框架中已内置的xVal非常相似的功能,因此由您决定使用哪个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.