MVC 4 ModelBinder的 [英] MVC 4 ModelBinder

查看:117
本文介绍了MVC 4 ModelBinder的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在MVC 4创建自定义的 IModelBinder ,它已被更改。

这是必须要实施的新方法是:

 布尔BindModel(HttpActionContext ActionContext中,ModelBindingContext的BindingContext);


解决方案

有2 IModelBinder接口:


  1. <$c$c>System.Web.Mvc.IModelBinder这是相同的$ p中$ pvious版本和没有改变

  2. <$c$c>System.Web.Http.ModelBinding.IModelBinder它用于由Web API和ApiController。所以基本上这个方法里面,你必须设置 actionContext.ActionArguments 到相应的值。你不再返回模型实例。

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);

解决方案

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.

这篇关于MVC 4 ModelBinder的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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