Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

asp.net mvc - How do I create a custom model binder using the `BindModel(HttpActionContext actionContext...` signature?

I need to know how to create a custom IModelBinder in MVC 4 and it has been changed.

The new method that has to be implemented is :

bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are 2 IModelBinder interfaces:

  1. System.Web.Mvc.IModelBinder which is the same as in previous versions and hasn't changed
  2. System.Web.Http.ModelBinding.IModelBinder which is used by the Web API and the ApiController. So basically inside this method you must set the actionContext.ActionArguments to the corresponding values. You no longer return a model instance.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...