Why can't I register a custom model binder for a List<int>?
- by quarksoup
I have an action that looks like
public ActionResult GetUsers(List<int> userIds) {//do stuff}
The list of userIds can become quite long, so I want to use Json.Net to deserialize it. To do so I created an IModelBinder implementation, which works fine for other objects, but never gets called for a List. The IModelBind looks like this
public class JsonBinder : System.Web.Mvc.IModelBinder
{
public object BindModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext)
{ //Do model binding stuff using Json.Net }
}
And I register this model binder with this line
ModelBinders.Binders.Add(typeof(List<int>), new JsonBinder());
However the JsonBinder is never called. Why is this? Should I be using a ValueProvider?