I'm creating a GET endpoint in my ASP.NET MVC web API project which is intended to take a an integer array in the URL like this:
api.mything.com/stuff/2,3,4,5
This URL is served by an action that takes an int[]
parameter:
public string Get(int[] ids)
By default, the model binding doesn't work - ids
is just null.
So I created a model binder which creates an int[]
from a comma-delimited list. Easy.
But I can't get the model binder to trigger. I created a model binder provider like this:
public override IModelBinder GetBinder(HttpConfiguration configuration, Type modelType)
{
if (modelType == typeof(int[]))
{
return new IntArrayModelBinder();
}
return null;
}
It's wired up so I can see it execute on startup but still my ids parameter remains stubbornly null.
What do I need to do?