What is the better ASP.NET MVC 3.0 Custom Validation approach
I am looking into ASP.NET MVC 3.0 custom validation and found some articles about that:
First: http://tdryan.blogspot.com/2010/12/aspnet-mvc-3-custom-validation.html
Second: http://thepursuitofalife.com/asp-net-mvc-3-unobtrusive-javascript-validation-with-custom-validators/
Third: http://samipoimala.com/it/2010/11/29/unobtrusive-client-validation-in-asp-net-mvc-3/
But each of articles describing a bit different approaches...
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.
In Second article they created just ValidatonAttribute
witch implemented IClientValidatable
then they crating custom jQueryValidator method on client side.
In the Third article they crating ModelClientValidator
inherited from ModelClientValidationRule
plus jQuery custom validator method on client side.
It is a bit confu开发者_Go百科sing 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.
Should i inherit my custom validator from DataAnnotationsModelValidator
of from ModelClientValidationRule
?
But may be some have any opinions on that?
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.
Hope it helps!
精彩评论