This project is read-only.

Fix for Patch 4179 [Client side validation of child properties (validate n levels in model type hierachy tree)]

Oct 20, 2009 at 10:52 AM

About patch 4181 I did not think about using two or more controls which was the easy and fastest way to go. Thanks John!!!

But for this to work I had to make a change in DataAnnotationsValidationRunner.cs so any property that is non primitive or class must be ignored as in the following case:


public class Booking
public string ClientName { get; set; }

[Range(1, 20)]
public int NumberOfGuests { get; set; }

public TripDates Dates { get; set; }

public class TripDates
public DateTime From { get; set; }

public DateTime To { get; set; }


I have one control to validate Booking class and one to validate TripDates. The change makes DataAnnotationsValidationRunner ignore the Dates property of Booking class cause:

  1. There is no way the control will be able to contruct the instance of TripDates to validate it
  2. I´m using a second control to validate Tripdates.

Let me know if this is important to you so I can submit the patch.

Carlos Mendible



Oct 20, 2009 at 4:28 PM

My initial thought would be to remove the [Required] attribute on Booking.TripDates. I wonder how xVal handles complex property types ... I'll have to take a look.

Oct 20, 2009 at 4:35 PM

Removing the Requiered attribute from Dates properties would let my custom validation framework (NHibernate.Validator + DataAnnotations + CSLA ) accept null values for that property in Booking class which is not correct.

I´ll look at XVal too and let you know.


Oct 20, 2009 at 4:47 PM

I thought you might say that :). Here's something that might help:

Rob Sutherland's answer looks pretty close, but I would use prop.Attributes.OfType<ValidationAttribute>() (like DataAnnotationsValidationRunner) instead of a marker interface. That would fix DataAnnotationsValidationRunner.GetErrors(), but not the client validation rules. I'll keep looking as I have time.


Oct 23, 2009 at 2:11 PM

I created Work Item for this: