title: Posting simple array to controller
body: <p>Posting an array of <code>ints</code> to my <code>MVC</code> controller seems to result in the value being <code>null</code>.</p>
  
  <p>The form data (parsed), indicates that each element in the array is posted individually:</p>
  
  <pre><code>ids[]:39
  ids[]:54
  </code></pre>
  
  <p>Which seems to make sense as I read that form data can only be posted as key/value pairs.</p>
  
  <p>My controller action is defined as follows:</p>
  
  <pre><code>[HttpPost]
  [Authorize]
  public JSONResult SubmitApprovedUploadedPhotoIds(List&lt;int&gt; ids)
  {
      try
      {
          if (ids == null)
              throw new ArgumentNullException("ids");
  
          // ...
      }
      // ...
  }
  </code></pre>
  
  <p>The main portion of my ajax POST:</p>
  
  <pre><code>// `ids` is an array of ints
  
  $.ajax({
  
      url: "/MyController/SubmitApprovedUploadedPhotoIds",
      cache: false,
      data: 
          {
              ids: ids
          },
      dataType: "json",
      type: "POST",
  });
  </code></pre>
  
  <p><strong>I would like the array of posted ids to populate the <code>ids</code> variable in the <code>MVC</code> action.</strong></p>
  
  <p>I have tried changing the post code to:</p>
  
  <pre><code>{
      ids: $(ids).serializeArray()
  },
  </code></pre>
  
  <p>and have tried changing my <code>MVC</code> action to:</p>
  
  <pre><code>public JSONResult SubmitApprovedUploadedPhotoIds(int[] ids)
  </code></pre>
  
  <p>with no success.</p>