views:

124

answers:

2

I'd like to be able to swap model binders out on a per Controller or per ActionMethod basis.

AFAIK the only options supported by the framework are to bind a model binder to a specific type.

How could I change my model binder per Controller or per ActionMethod in a clean way?

+1  A: 

You can use ModelBinderAttribute. Example

[HttpPost]
public ActionResult CreateTask([ModelBinder(typeof(TaskBinder))] Task task)
LukLed
"instead of by type or with attributes?"
jfar
A: 

I would suggset you to implement a Composite model binder like here

http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/11/19/a-better-model-binder-addendum.aspx

It's a kind a chain of responsabilities and the model binder that can handle the bind will be applied.

Thomas Jaskula