Changing model binding to controller instead of type or attributes?

I would like to be able to exchange model bindings on each controller or on ActionMethod.

AFAIK, the only parameters supported by the platform are the binding of the model binding to a specific type.

How can I change my connecting device to a controller or to ActionMethod in a clean way?

+3
source share
2 answers

You can use ModelBinderAttribute. Example

[HttpPost]
public ActionResult CreateTask([ModelBinder(typeof(TaskBinder))] Task task)
+1
source

I would advise you to implement binding with a composite model, as here

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

, .

0

Source: https://habr.com/ru/post/1726738/


All Articles