ObjectCollectionValidator: How to get the fullpath to the object in error?

Topics: Validation Application Block
Jul 1, 2009 at 10:32 AM

In my ASP.NET MVC app I want to show validation errors to the user for a list of input boxes, that each represent an order, and have the error message placed at the correct input box. In my domain model I have an object, Customer, that has several lists of Orders. It has NewOrders, PriorityOrders and OldOrders. I use ObjectCollectionValidator via an attribute on these Order list properties in the Customer class. The ValidationResult only tells me that an Order object has failed, but not from which list of Orders, and not at what index in the list.
Am I missing something that would make it possible for me to have the ValidationResult tell me this?
If the ValidationResult could tell me e.g. that "Customer.PriorityOrders[5].Title" has failed, I would be able to show precisely which order has failed, to the user.

Right now the only solution I see, is to write my own Custom ObjectCollectionValidator that will return the missing information in the ValidationResult.

Any help is appreciated, thanks.

Jul 1, 2009 at 10:44 AM

Unfortunately, there's no easier way to do that, in fact, the ObjectCollectionValidator does not provide any message template token. 

 

Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.
entlib.support@avanade.com

 

Jul 1, 2009 at 11:00 AM

Thanks for the quick reply Sarah!

I will start implementing a CustomObjectCollectionValidator soon then. It looks like it is not a great amout of work, as it is only a few lines of code in the original ObjectCollectionValidator's DoValidate method that needs to be changed. I think I will create a seperate custom validator, so I don't have to recompile EntLib and possibly get out of sync with the EntLib codebase.

If anyone has something to add, it is very welcome.