Why can't I register a custom model binder for a List<int>?
Posted
by
quarksoup
on Stack Overflow
See other posts from Stack Overflow
or by quarksoup
Published on 2013-06-26T16:19:56Z
Indexed on
2013/06/26
16:21 UTC
Read the original article
Hit count: 161
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?
© Stack Overflow or respective owner