Using asp.net mvc model binders generically

Posted by Sean Chambers on Stack Overflow See other posts from Stack Overflow or by Sean Chambers
Published on 2009-11-14T01:10:47Z Indexed on 2010/05/11 3:14 UTC
Read the original article Hit count: 250

Filed under:
|
|
|

I have a hierarchy of classes that all derive from a base type and the base type also implements an interface. What I'm wanting to do is have one controller to handle the management of the entire hierarchy (as the actions exposed via the controller is identical). That being said, I want to have the views have the type specific fields on it and the model binder to bind against a hidden field value. something like:

<input type="text" name="model.DerivedTypeSpecificField" />
<input type="hidden" name="modelType" value="MyDerivedType" />

That being said, the asp.net mvc model binders seem to require the concrete type that they will be creating, because of that reason I would need to create a different controller for every derived type.

Has anyone does this before or know how to manipulate the model binder to behave in this way? I could write my own model binder, but I'm not wanting anything past the basic model binding behavior of assign properties and building arrays on the target type.

Thanks!

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about c#