title: Asp.Net MVC 4 Automatically bind model from array of objects in form post
body: <p>I have built an array of objects in JavaScript and want to post them back to the server via Ajax (Im using jQuery)</p>
  
  <p>The JavaScript object array looks like this:</p>
  
  <pre><code>var columns = [
      { name: 'col 1', source: 'whatever', hidden: false, width: 50 },
      ...
  ];
  </code></pre>
  
  <p>Im posting it back like this:</p>
  
  <pre><code>$.post('/MyController/MyAction', { 'columns': columns });
  </code></pre>
  
  <p>On the controller action Im currently getting this:</p>
  
  <p><img src="https://i.stack.imgur.com/J095f.png" alt="enter image description here"></p>
  
  <p>I have a c# object called <code>JqColumn</code> that I want to bind the post into, it looks like this:</p>
  
  <pre><code>public class JqGridColumn
  {
      public string name;
      public string source;
      public int width;
      public bool hidden;
  }
  </code></pre>
  
  <p>So I thought that adding a parameter in the controller action of type <code>JqGridColumn[] columns</code> would automatically bind the posted data, but it doesn't (it generates a array, with the correct number of elements, but each item in the array has blank values)</p>
  
  <p>Can anyone tell me what Im doing wrong? Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>At present, I am manually binding the items in my controller action as follows:</p>
  
  <pre><code>    public void ColumnChooser(JqGridColumn[] columns)
      {
          for (int i = 0; i &lt; columns.Length; i++)
          {
              columns[i].hidden = bool.Parse(Request.Form["columns[" + i + "][hidden]"]);
              columns[i].width = int.Parse(Request.Form["columns[" + i + "][width]"]);
              columns[i].name = Request.Form["columns[" + i + "][name]"];
              columns[i].source = Request.Form["columns[" + i + "][source]"];
          }
          return;
      }
  </code></pre>
  
  <p>...which works fine, but I'd really like to know the .Net MVC (correct) way to do it!</p>