title: ajax pass object to controller
body: <p>HomeController:  </p>
  
  <pre><code>      [HttpPost]
        public JsonResult SetDefaultHomeCategoryOrder(CategoryOrderModel categories)
              {
  
  
                  return Json(new { msg = "ok" });
              }
  
              public class CategoryOrderModel
              {
                  public int DisplayOrder;
                  public int CategoryId;
              }
  
  
  View: 
  
                       var operationCollection = new CategoryOrderModel();
  
  
        $.ajax({
                      url: '@Url.Action("SetDefaultHomeCategoryOrder", "Home")',
                      dataType: 'json',
                      data: JSON.stringify(operationCollection),
                      type: 'POST',
                      contentType: "application/json; charset=utf-8",
                      success: function (data) {
                          alert(data.msg);
  
                      },
                      error: function (data) {
                          alert('error');
                      }
                  });
  </code></pre>
  
  <p>The controller never gets the correct parameter??</p>
  
  <p>UPDATED: I changed the code to accept the collection</p>
  
  <pre><code>[HttpPost]
          public JsonResult SetDefaultHomeCategoryOrder(List&lt;CategoryOrderModel&gt; categories)
          {         
  
              return Json(new { msg = 'ok' });
          }
  </code></pre>
  
  <p>View:  </p>
  
  <pre><code> var collection = [];
   var col1= new CategoryOrderModel(1,2);
   collection.push(col1);
  var col2= new CategoryOrderModel(2,5);
   collection.push(col2);
  $.ajax({
              url: '/Home/SetDefaultHomeCategoryOrder/',
              dataType: 'json',
              data: '{ categories : ' + JSON.stringify(collection) + '}',
              type: 'POST',
              contentType: "application/json; charset=utf-8",
              success: function (data) {
                  alert(data.msg);
  
              },
              error: function (data) {
                  alert('error');
              }
          });
  
  
  function CategoryOrderModel(displayOrder, categoryId) {
          var self = this;
          self.DisplayOrder = displayOrder;
          self.CategoryId = categoryId;
      }
  </code></pre>