本文介绍了如何使用`BindModel(HttpActionContext actionContext ...`'签名创建自定义模型联编程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在MVC 4中创建自定义IModelBinder,并且已对其进行了更改.

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

必须实现的新方法是:

bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext);

推荐答案

有2个IModelBinder接口:

There are 2 IModelBinder interfaces:

  1. System.Web.Mvc.IModelBinder 与以前的版本相同,并且未更改
  2. System.Web.Http.ModelBinding.IModelBinder ,由Web API和ApiController使用.因此,基本上在此方法内,您必须将actionContext.ActionArguments设置为相应的值.您不再返回模型实例.
  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.

这篇关于如何使用`BindModel(HttpActionContext actionContext ...`'签名创建自定义模型联编程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:47