title: Posting JSON Data containing an array to Controller Action
body: <p>In an ASP.NET MVC3 application, I'm trying to use jQuery to make an asynchronous post to an action.</p>
  
  <p>The following JSON object is being passed as data...</p>
  
  <pre><code>{
      categoryId: "21"
      content: "asdf"
      reference: "asdf"
      tags: [
          {id: 1, name: "asdf", status: 1},
          {id: 2, name: "asdf", status: 1},
          {id: 3, name: "asdf", status: 1}
      ]
  }
  </code></pre>
  
  <p>The method signature I have to receive the request is</p>
  
  <pre><code>[HttpPost]
  public ActionResult Create(String reference, Int32? categoryId, String content, IEnumerable&lt;TagDTO&gt; tags)
  </code></pre>
  
  <p>with TagDTO is being defined as:</p>
  
  <pre><code>public class TagDTO
  {
      public String name { get; set; }
      public Int32 id { get; set; }
      public Int32 status { get; set; }
  }
  </code></pre>
  
  <p>I should mention that before I introduced the array of objects to the JSON object and to the signature of the action method, this was working perfectly.  And the Post is still successfully reaching the action, only the data in the IEnumerable is not coming through correctly.  It will give me the correct number of objects in the IEnumerable, but they are all initialized to default values. (id=0, name=null, status=0)</p>
  
  <p>I'm not sure what I'm doing wrong here.  I hope this makes sense.  I'm hoping someone can show me the proper way to pass data to an MVC action in this manner.</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>Here is the javascript function I'm using to perform my ajax call...</p>
  
  <pre><code>function saveResource() {
      var tagAssignments = [];
      for (var x = 0; x &lt; $('.tag-assignment').length; x++) {
          var tag = $($('.tag-assignment')[x]);
          tagAssignments.push({
              name: tag.find('.tag-name').html().toString(),
              id: parseInt(tag.find('.tag-id').html()),
              status: parseInt(tag.find('.tag-status').html())
          });
      }
  
      $.ajax({
          url: '/Resources/Create',
          dataType: 'json',
          type: 'POST',
          success: function (data) {
              if (data.status == 'Success') {
                  forwardToDefaultPage();
              } else {
                  alert(data.status);
              }
          },
          data: {
              reference: $('#txt-resource-reference').val(),
              categoryId: $('#ddl-category').val(),
              content: $('#txt-resource-content').val(),
              tags: tagAssignments
          }
      });
  }
  </code></pre>