【发布时间】:2015-09-01 16:34:04
【问题描述】:
web api 中的默认绑定器
http://url.com/webapi/Report/?PageIds=3243&PageIds=2365
绑定到
public IHttpActionResult Report(List<int> PageIds){ // exciting webapi code}
我想绑定 http://url.com/webapi/Report/?PageIds=3243,2365
因为我的 URL 空间不足,无法执行 GET。
我创建了一个类 公共类 CommaSeparatedModelBinder :
System.Web.Http.ModelBinding.IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
//Binding in here
}
}
并在我的WebApiConfig.cs注册了这个
var provider = new SimpleModelBinderProvider(
typeof(List<int>), new CommaSeparatedModelBinder());
config.Services.Insert(typeof(ModelBinderProvider), 0, provider);
我已经更改了我的方法签名以像这样使用模型绑定器
public IHttpActionResult Report( [ModelBinder] List<int> PageIds){ // exciting webapi code}
但是我的活页夹中的断点没有被击中(并且列表没有被绑定)。
我还需要配置什么?
【问题讨论】:
标签: c# asp.net-web-api model-binding