【发布时间】:2015-11-05 04:23:28
【问题描述】:
我正在实施自定义模型绑定器。我研究了如何做到这一点,发现在 WebApi 的情况下我需要实现IModelBinder 接口。
我的实现如下所示:
public class ModelBaseBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
if ((bindingContext.Model is MyModel))
{
//my code here
controller.InitModel(model);
return true;
}
return false;
}
}
我只是不确定我的实施是否完整。我是否需要调用任何默认 WebApi BindModel 才能使我的自定义实现工作?
【问题讨论】:
标签: asp.net-web-api2 asp.net-web-api custom-model-binder