Per my previous question , I applied a model binder that displays /api/v1/widgets/1,2,3 in
// WidgetsController.cs: public ActionResult Show(IEnumerable<int> idArgs) { }
This worked for a while, but now it is no longer so. My ModelBinder is not even called at all. When my action is called, idArgs has the value of an empty list, even if I set its default value to null in the route, which suggests me that the default connecting device thinks it is getting some kind of value. The only change I made from last week when it was working is that I previously called my ShowMany. action ShowMany. . Since then I renamed it Show . Can someone help me understand why my ModelBinder is not being called?
In global.asax.cs I have
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); ValueProviderFactories.Factories.Add(new JsonValueProviderFactory()); ModelBinders.Binders.Add(typeof(IEnumerable<int>), new IEnumerableOfIntCSVModelBinder()); }
And the route looks like this (I checked that this route is used):
context.MapRoute( "show", "api/{controller}/{idArgs}", new { action = "show" }, new { httpMethod = new HttpMethodConstraint("GET"), idArgs = @"^(\d+,)+\d+,?$" } );
Edit: I already tried messing messing with routes, as well as commenting on JsonValueProvider , and I still get an empty array. In my controller I can do
var ids = RouteData.Values["idArgs"];
and get the string "1,2,3". If only the infrastructure passes this to my ModelBinder, my ModelBinder will turn it into IEnumerable .
I am using AutoFac. Is it possible that AutoFac injects an empty array into my controller method? I had no such problems elsewhere (and we use AutoFac everywhere in this project.)
Edit2 . I also tried to decorate both the idArgs action parameter and the controller with [ModelBinder(typeof(IEnumerableOfIntCSVModelBinder))] , but this did not affect.