title: Posting JSON array of object to controller in ASP.NET MVC
body: <p>I'm trying to post an array of objects to my controller via JSON. When sending a single object, the MVC model binding is working fine, but when I try and send an array of objects, the binding fails completely and I receive a null object in my controller action. </p>
  
  <p>First, here is the ViewModel I am working with:</p>
  
  <pre><code>public class ForecastViewModel
      {
          public int RestaurantCode { get; set; }
          public System.DateTime FiscalDate { get; set; }
          public Nullable&lt;decimal&gt; ForecastSales { get; set; }
          public Nullable&lt;decimal&gt; ForecastFOHLabour { get; set; }
          public Nullable&lt;decimal&gt; ForecastFOHHours { get; set; }
          public Nullable&lt;decimal&gt; ForecastBOHLabour { get; set; }
          public Nullable&lt;decimal&gt; ForecastBOHHours { get; set; }
          public Nullable&lt;decimal&gt; ForecastFoodSales { get; set; }
  
          public ForecastViewModel() { }
  
          public ForecastViewModel(Forecast model){...}
      }
  </code></pre>
  
  <p>And the controller action:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Update(List&lt;ForecastViewModel&gt; model){...}
  </code></pre>
  
  <p>And here is the raw JSON being sent to my controller:</p>
  
  <pre><code>[{"RestaurantCode":1002,"FiscalDate":"2/24/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/25/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/26/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/27/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/28/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/29/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"},{"RestaurantCode":1002,"FiscalDate":"2/30/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"}] 
  </code></pre>
  
  <p>I went back and modified the code to send a single instance of a ForecastViewModel to my controller instead of an array, and the binding worked perfectly:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Update(ForecastViewModel model){...}
  </code></pre>
  
  <p>Here is the JSON I was sending the controller action:</p>
  
  <pre><code>{"RestaurantCode":1002,"FiscalDate":"2/24/2014","ForecastSales":"111","ForecastFOHLabour":"111.11","ForecastFOHHours":"11","ForecastBOHLabour":"111.11","ForecastBOHHours":"11","ForecastFoodSales":"111.11","FOHPercent":"100.1","BOHPercent":"100.0"}
  </code></pre>
  
  <p>How can I modify my code so that the binding works against the array of objects?</p>
  
  <p>UPDATE:
  Here is the javascript that sends the request. I'm using knockout.js to serialize my array of objects to JSON.</p>
  
  <pre><code>self.save = function () {
      var forecasts = ko.toJSON(self.forecasts);
  
      console.log(forecasts)
  
      $.ajax({
          type: "POST",
          url: "/Tools/Forecasts/Update/",
          dataType: "application/json",
          data: forecasts
      }).done(function(data){
          alert("complete!");
      });
  };
  </code></pre>