title: Null parameter in controller from ajax
body: <p>When a user clicks a save button, a JavaScript function uses AJAX to call the Controller and send over JSON data about the objects. </p>
  
  <p><strong>JavaScript Function</strong></p>
  
  <pre><code>$.ajax({
          url: "/Data/sendFridgeItems?items=" + JSON.stringify($scope.items.data),
          type: "POST",
          data: JSON.stringify($scope.items.data),
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          success: function () {
              console.log("good!");
          },
          error: function () {
              console.log("error");
          }
      });
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult SendFridgeItems(string items)
      {
          fridge[] fridgeItems = JsonConvert.DeserializeObject&lt;fridge[]&gt;(items);
          foreach (fridge item in fridgeItems)
          {
              bool exists = cookDB.fridges.AsEnumerable()
                  .Any(x =&gt; x.Name == item.Name &amp;&amp; x.Purchased == item.Purchased &amp;&amp; x.Count == item.Count);
              if (!exists)
              {
                  cookDB.fridges.Add(item);
                  cookDB.SaveChangesAsync();
              }
          }
          return null;
      }
  </code></pre>
  
  <p>It works, but I don't think the way of sending my data through the url parameter is correct in my situation, because the data will be big enough. I wanted to know if there is a better way to send my data to the controller?</p>
  
  <p>I tried to send it this way, but the controller receives null value.</p>
  
  <pre><code>$.ajax({
          url: "/Data/sendFridgeItems",
          type: "POST",
          data: JSON.stringify($scope.items.data),
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          success: function () {
              console.log("good!");
          },
          error: function () {
              console.log("error");
          }
      });
  </code></pre>
  
  <p><strong>JSON of $scope.items.data</strong></p>
  
  <pre><code>[{"id":2,"name":"Item1","count":2,"type":"pcs.","purchased":"12/09/2017","wasted":"15/10/2017","cam":"Freezer","comment":"no comment","$$hashKey":"object:38"},{"id":3,"name":"Item2","count":30,"type":"g.","purchased":"15/01/1880","wasted":"21/03/1882","cam":"Cooler","comment":"commented","$$hashKey":"object:39"}]
  </code></pre>
  
  <p><strong>$scope.items</strong></p>
  
  <pre><code>$scope.items = {
      "count": 2,
      "data": [
        {
            "name": "Item1",
            "count": 2,
            "type": "pcs.",
            "purchased": "12/09/2017",
            "wasted": "15/10/2017",
            "cam": "Freezer",
            "comment": "no comment"
        },
    {
            "name": "Item2",
            "count": 30,
            "type": "g.",
            "purchased": "15/01/1880",
            "wasted": "21/03/1882",
            "cam": "Cooler",
            "comment": "Commented"
        }
      ]
  };
  </code></pre>
  
  <p><strong>Fixed Controller For N.Ivanov's solution (this controller+ N.Ivanov's ajax = solution)</strong></p>
  
  <pre><code>public ActionResult SendFridgeItems(fridge[] items)
      {
          fridge[] fridgeItems = JsonConvert.DeserializeObject&lt;fridge[]&gt;(items.ToString());
          foreach (fridge item in items)
          {
              bool exists = cookDB.fridges.AsEnumerable()
                  .Any(x =&gt; x.Name == item.Name &amp;&amp; x.Purchased == item.Purchased &amp;&amp; x.Count == item.Count);
              if (!exists)
              {
                  cookDB.fridges.Add(item);
                  cookDB.SaveChangesAsync();
              }
          }
          return null;
      }
  </code></pre>