什么是更好的ASP.NET MVC 3.0自定义验证方法 [英] What is the better ASP.NET MVC 3.0 Custom Validation approach
问题描述
我期待到ASP.NET MVC 3.0自定义验证,发现有关的一些文章:
I am looking into ASP.NET MVC 3.0 custom validation and found some articles about that:
第一: HTTP ://tdryan.blogspot.com/2010/12/aspnet-mvc-3-custom-validation.html
二:<一href=\"http://thepursuitofalife.com/asp-net-mvc-3-unobtrusive-javascript-validation-with-custom-validators/\" rel=\"nofollow\">http://thepursuitofalife.com/asp-net-mvc-3-unobtrusive-javascript-validation-with-custom-validators/
第三:http://samipoimala.com/it/2010/11/29/unobtrusive-client-validation-in-asp-net-mvc-3/
但每次的描述有点不同的方法的文章...
But each of articles describing a bit different approaches...
在首页的文章,他们创建 CustomValidatonAtribute
和 CustomValidaor
继承的形式 DataAnnotationsModelValidator&LT; CustomValidatonAtribute方式&gt;
,比他们登记所有在 Global.asx
,没有任何jQuery的定制validaton方法
In the First article they creating CustomValidatonAtribute
and CustomValidaor
Inherited form DataAnnotationsModelValidator<CustomValidatonAtribute>
, than they register all that in Global.asx
, without any jQuery custom validaton methods.
在二的文章,他们创造 IClientValidatable
实施只是 ValidatonAttribute
巫婆然后他们装箱定制jQueryValidator方法在客户端。
In Second article they created just ValidatonAttribute
witch implemented IClientValidatable
then they crating custom jQueryValidator method on client side.
在第三的文章,他们装箱 ModelClientValidator
从 ModelClientValidationRule
继承加上jQuery的自定义验证方法上的客户端。
In the Third article they crating ModelClientValidator
inherited from ModelClientValidationRule
plus jQuery custom validator method on client side.
这是一个有点混乱挑哪种方法,但我认为Ø将与第三一种第一是找我更加轻便了其他的去了。
It is a bit confusing which approach to pick, but i think o would go with Third one first it is looking for me more lightweight that other ones.
我知道我可能需要尝试他们每个人看到它是如何看的做法,看起来是取决于需要什么样的检验。
I know that i may need to try each of them to see how it is looking on practice and looks like it is depends what validation is required.
我应该继承 DataAnnotationsModelValidator
我的自定义验证从 ModelClientValidationRule
?
Should i inherit my custom validator from DataAnnotationsModelValidator
of from ModelClientValidationRule
?
不过,可能有些对此有何看法?
But may be some have any opinions on that?
推荐答案
。但我终于用 System.Web.Mvc.RemoteAttribute
在客户机上验证。而对于服务器我做,从ValidationAttribute继承一个验证器类,我覆盖的方法保护覆盖的ValidationResult的IsValid
。对于我是最简单的选择。
for my also was confuse. But I finally use the System.Web.Mvc.RemoteAttribute
for validation on the client. And for the server I make a validator class that inherit from ValidationAttribute and I override the method protected override ValidationResult IsValid
. For my was the easiest option.
希望它帮助!
这篇关于什么是更好的ASP.NET MVC 3.0自定义验证方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!