如何使用`BindModel(HttpActionContext actionContext...` 签名创建自定义模型绑定器? [英] How do I create a custom model binder using the `BindModel(HttpActionContext actionContext...` signature?

查看:18
本文介绍了如何使用`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...` 签名创建自定义模型绑定器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆