If so, it really should validate complex ViewModels down to the last properties. If not, try using that instead of the DataAnnoationsModelRunner you are using. This blog article blog article on Client-Side Validation with xVal shows how The first version of the DataAnnotationModelBinder had a bug that would make it crash when used with complex viewmodels.
Perhaps there is a new version out which fixes the crash but ignores complex models? In any case, I'd suggest giving the version of the DataAnnotationModelBinder used in the demo project of the blog article linked above a try. I am using it in my own real-world project and it does work on complex viewmodels Regarding your second question "Is there a supported way of handling child object validation with xVal : You haven't posted any code residing on ASPX forms, but you might also be referring to the fact that a only adds client-side validation to immediate properties of that Model Type, but not properties of child objects.
You can simply circumvent the problem by using multiple ClientSideValidation statements, for example: %= Html. ClientSideValidation()%> ("ChildModelPropertyName")%.
If so, it really should validate complex ViewModels down to the last properties. If not, try using that instead of the DataAnnoationsModelRunner you are using. This blog article blog article on Client-Side Validation with xVal shows how.
The first version of the DataAnnotationModelBinder had a bug that would make it crash when used with complex viewmodels. Perhaps there is a new version out which fixes the crash but ignores complex models? In any case, I'd suggest giving the version of the DataAnnotationModelBinder used in the demo project of the blog article linked above a try.
I am using it in my own real-world project and it does work on complex viewmodels. Regarding your second question "Is there a supported way of handling child object validation with xVal": You haven't posted any code residing on ASPX forms, but you might also be referring to the fact that a only adds client-side validation to immediate properties of that Model Type, but not properties of child objects. You can simply circumvent the problem by using multiple ClientSideValidation statements, for example: ()%> ("ChildModelPropertyName")%.
The second answer does work, but breaks down if you have multiple properties on the parent object that all associate the same child type, but with different propeties. Ie. User BillingAddress ShippingAddress It looks as if you could tweak the xval.
Jquery validation utility to fix this however. – Sean Chambers Feb 21 '10 at 17:59.
I had the same problem. I needed to validate complex objects that can appear as a property of another object. I haven't gotten into client side validation (yet), but the idea from Adrian Grigore about multiple html.
ClientSideValidation() seems like it may be the ticket there. I ended up creating a marker interface that marks all the classes that I need to validate. It could be an attribute or you could use this idea for all properties of a class.
Basically it validates the object using the DataAnnotationsValidationRunner you mention above and then iterates over the properties of the object and runs the DataAnnotationsValicationRunner over all of those until there are no more to check. Here's pseudo code for what I did: IEnumarable GetErrors(object instance) { List errors = new List(); errors. AddRange(GetDataAnnotationErrors(instance)); errors.
AddRange(GetPropertyErrors(instance)); return errors; } IEnumerable GetDataAnnotationErrors(object instance) { // code very similar to what you have above } IEnumearable GetPropertyErrors(object instance) { var errors = new List(); var objectsToValidate = instance.GetType().GetProperties(). Where(p => p.PropertyType.GetInterface(). Contains(typeof(IMarkerInterface))); // the call above could do any type of reflecting over the properties you want // could just check to make sure it isn't a base type so that all custom // object would be checked if(objectsToValidate == null) return errors; foreach(object obj in objectsToValidate) { errors.
AddRange(GetDataAnnotationErrors(obj)); errors. AddRange(GetPropertyErrors(obj)); } return errors; } I hope this is clear. I've been testing this system on domain objects and so far so good.
Working out a few kinks here and there, but the idea has proven sound for what I'm doing.
I needed to validate complex objects that can appear as a property of another object. I haven't gotten into client side validation (yet), but the idea from Adrian Grigore about multiple html. ClientSideValidation() seems like it may be the ticket there.
I ended up creating a marker interface that marks all the classes that I need to validate. It could be an attribute or you could use this idea for all properties of a class. Basically it validates the object using the DataAnnotationsValidationRunner you mention above and then iterates over the properties of the object and runs the DataAnnotationsValicationRunner over all of those until there are no more to check.
I hope this is clear. I've been testing this system on domain objects and so far so good.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.