3

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 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.

Should i inherit my custom validator from DataAnnotationsModelValidator of from ModelClientValidationRule?

But may be some have any opinions on that?

b4hand
  • 9,550
  • 4
  • 44
  • 49
Vasya Pupkin
  • 645
  • 1
  • 11
  • 18

1 Answers1

0

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!

elranu
  • 2,292
  • 6
  • 31
  • 55
  • i think remote validation is nice to have when you need to check something in data base (e.g: User Name or Email is already exists, etc) otherwise i would use real client unobtrusive validation. – Vasya Pupkin May 31 '11 at 02:07
  • True... I use it in that case. – elranu May 31 '11 at 02:14