title: How would I create a model binder to bind an int array?
body: <p>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:</p>
  
  <pre><code>api.mything.com/stuff/2,3,4,5
  </code></pre>
  
  <p>This URL is served by an action that takes an <code>int[]</code> parameter:</p>
  
  <pre><code>public string Get(int[] ids)
  </code></pre>
  
  <p>By default, the model binding doesn't work - <code>ids</code> is just null.</p>
  
  <p>So I created a model binder which creates an <code>int[]</code> from a comma-delimited list. Easy.</p>
  
  <p>But I can't get the model binder to trigger. I created a model binder provider like this:</p>
  
  <pre><code>public override IModelBinder GetBinder(HttpConfiguration configuration, Type modelType)
  {
    if (modelType == typeof(int[]))
    {
      return new IntArrayModelBinder();
    }
  
    return null;
  }
  </code></pre>
  
  <p>It's wired up so I can see it execute on startup but still my ids parameter remains stubbornly null.</p>
  
  <p>What do I need to do?</p>