views:

350

answers:

2

Hello to everybody. 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 generate the appropriate client-side validation hints.

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

A: 

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.

bug0r
Actualy, I'm looking for the client validation wich works like here http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx look step 3. So as I can understand it's not possible to implement such client validation with your's framework becouse it's too flexible, so you can't generate rules in JavaScript to handle validation in client. But EntLib has determinated validators, wich can be described with JavaScript in the similar way data annotations does. But becouse of the composite pattern it's impossible to get list of validators to create JavaScript metadata.
er-v
A: 

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/

er-v