Note: Thank you for visiting my blog. However, this blog is not maintained actively anymore. This post is now also in my new blog. Feel free to leave a comment there.
As discussed in my last post EntLib VAB doesn't support client side validation (in js/jQuery) out-of-the-box. And also while validating object graph, EntLib VAB generate Validation Result keys which are different from the ModelState keys in MVC.
As discussed in my last post EntLib VAB doesn't support client side validation (in js/jQuery) out-of-the-box. And also while validating object graph, EntLib VAB generate Validation Result keys which are different from the ModelState keys in MVC.
In this post we will discuss on this problem.
Solution to this problem is simple. We just need to create an adapter for EntLib VAB validator to MVC ValidationAttribute, i.e. a piece of code is needed that will read the EntLib Validation configuration xml and for each validator it will return the MVC counterpart of the validator, i.e. ValidationAttribute.
As for aligning the validation error keys with MVC ModelState keys, we need to leverage the default model validation of ASP.NET MVC.
And the great news is that one single piece of code addresses combines these two solutions.