开发者

Asp.Net MVC 2 Client validation implementation for Enterprise Library Validation Block

I've found a very good article about how to use EntLib Validation Block for server validation in MVC 2. But as there pointed out

The current design of EntLib’s Validation Application Block uses the Composite pattern; that is, when we ask for validation for an object, it returns back a single validator object that contains a list of all the validation work to be done. While this is very convenient from a normal usage scenario, the unfortunate side-effect is that we can’t “peek inside” to see what the individual validations are that it’s doing, and therefore can’t gener开发者_Python百科ate the appropriate client-side validation hints.

So how is it possible to implement client side validation for EntLib? Is there work around?


So I could not find anything about this, so I desided to implement it on my own an publish it on codeplex http://elvalweb.codeplex.com/


Alexey, :-) i have my own implementation for validation task that is not related with EntLib, but very similar by concept. For developer it's look like the following:

   ValidationFactory.AddRule<IPerson>(
     x => string.IsNullOrEmpty(x.FirstName) &&
          string.IsNullOrEmpty(x.LastName),
     "Person should have a name", "validation set 1");
   IPerson p = UnityHelper.DefaultContainer.Resolve<IPerson>();
   ValidationResults res = ValidationFactory.Validate<IPerson>(p,"validation set 1");
   if(!res.IsValid)
   {
     foreach (ValidationResult vr in res)
     {
       var msg= vr.Message;
       var validated_instance = vr.Target;
       var Validator_instance = vr.Validator;
     }
   }   

If you are interesting in it let me know, i will cut it from my current project into separate solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜