views:

149

answers:

0

I have followed the the article on asp.net.mvc, Validating with a Service Layer. This all works fine until I come against a custom ModelBinder. If a form item fails validation within my Service Layer, I update my Validation Dictionary (which is the ModelState passed in by the calling Controller) and all is well. When the Controller passes the data back out to the View for the form item that failed validation I receive the error Object reference not set top an instance of an object..

From looking at this forum post, as well as ValueProviderResult and this Stackoverflow question, it is obvious why you need to add the SetModelValue. My issue is that the article specifically outlines (and as you always want to do anyway) decoupling the Service Layer so that it has no dependency on the MVC framework.

With that in mind, how could you add in a value representing ValueProviderResult into the Service Layer (as the article sets AddError and IsValid) considering that this type is from within the MVC framework itself?