views:

18

answers:

0

In an MVC2 app, I have various controller methods that will be handling incoming JSON data. I created a custom JSON ValueProvider that parses the data and makes the data available for binding.

I'd like to have various controller methods have as param type an (Edit/From/Whatever) Model to which to map the parsed JSON values. I have adapted the SmartBinder concept from Bogard's work because the JSON data the ValueProvider was parsing wasn't mapping properly using default binders.

For example, on a PatientController, I have a method with signature ActionResult Update(PatientInputModel records). As you can see, the lone param is of type PatientInputModel. When SmartBinder gets invoked, it reaches InputModelBinder.BindModel(), but I fear I'm not sure what's the best way to proceed inside there.

At this point, I have the fact that the bindingContext's ModelType is PatientInputModel and a ValueProvider is confirmed full of the parsed JSON.

How do I best get data from the ValueProviderCollection (And the JSONValueProvider, specifically) into my PatientInputModel?

PS: The way to solve this must be a little generic, because BindModel only knows at run-time what model type to map to, and they may be different between calls. IOW, InputModelBinder.BindModel() won't always be PatientInputModel. (However, they will all be subclassed from BaseInputModel.)