The default binder in web api expecst
http://url.com/webapi/Report/?PageIds=3243&PageIds=2365
To bind to
public IHttpActionResult Report(List<int> PageIds){ // exciting webapi code}
I wish to bind http://url.com/webapi/Report/?PageIds=3243,2365
as I am running out of space in my URL to do a GET.
I have created a class public class CommaSeparatedModelBinder :
System.Web.Http.ModelBinding.IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
//Binding in here
}
}
and registered this in my WebApiConfig.cs
var provider = new SimpleModelBinderProvider(
typeof(List<int>), new CommaSeparatedModelBinder());
config.Services.Insert(typeof(ModelBinderProvider), 0, provider);
I have altered my method signature to use the model binder like so
public IHttpActionResult Report( [ModelBinder] List<int> PageIds){ // exciting webapi code}
However a break point in my binder is not being hit (and the list does not get bound).
What else do I need to configure?