title: My AddtoCart Method in my MVC ShoppingCart app is returning Null when receiving the product details from TescoLabsApi:
body: <p>As I am getting the product information from the TescoLabs Api My method is returning null when I call the AddtoCart method: </p>
  
  <p>My MakeRequest method below shows this <a href="https://i.stack.imgur.com/IRrcd.png" rel="nofollow noreferrer">screen</a>: </p>
  
  <pre><code>public async Task&lt;ActionResult&gt; MakeRequest(string q)
  {
      System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
  
      var client = new HttpClient();
      client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "api key ");
  
      var uri = string.Format("https://dev.tescolabs.com/grocery/products/?query={0}&amp;offset={1}&amp;limit={2}", q, 0, 100);
  
      var response = await client.GetAsync(uri);
      string body = await response.Content.ReadAsStringAsync();
      var result = JObject.Parse(body);
  
      IList&lt;JToken&gt; results = result["uk"]["ghs"]["products"]["results"].Children().ToList();
  
      //// serialize JSON results into .NET objects
      IList&lt;Product&gt; products = new List&lt;Product&gt;();
      foreach (JToken r in results)
      {
          // JToken.ToObject is a helper method that uses JsonSerializer internally
          Product product = r.ToObject&lt;Product&gt;();
          products.Add(product);
      }
      return View(products);  
  </code></pre>
  
  <p>I have the AddToCart Method: </p>
  
  <pre><code>public void AddToCart(Product Product)
  {
      var cartItem = listDB.Carts.SingleOrDefault(c =&gt; c.CartId == ShoppingCartId &amp;&amp; c.Id == Product.ID);
      if (cartItem == null)
      {
          cartItem = new Cart
          {
              Id = Product.ID,
              CartId = ShoppingCartId,
              Count = 1,
              DateCreated = DateTime.Now
          };
          listDB.Carts.Add(cartItem);
      }
      else {
          cartItem.Count++;
      }
      listDB.SaveChanges();
  
  }
  </code></pre>
  
  <p>this is my ShoppingCartController with the ActionResult Method: </p>
  
  <pre><code>public ActionResult AddToCart(string name)
  {
      var addedProduct = listDB.products.FirstOrDefault(product =&gt; product.Name == name);
      var cart = ShoppingCart.GetCart(this.HttpContext);
      cart.AddToCart(addedProduct);
      return RedirectToAction("Index");
  }
  </code></pre>
  
  <p>but for some reason when I click in the Add button the exception below shows: </p>
  
  <pre><code>System.Reflection.TargetException was unhandled by user code
    HResult=-2146232829
    Message=Non-static method requires a target.
    Source=mscorlib
  </code></pre>
  
  <p>the product information is returning null <a href="https://i.stack.imgur.com/pyEoZ.png" rel="nofollow noreferrer">runtime exception</a></p>
  
  <p>How could I modify my <code>AddToCart</code> method to receive the product information from <code>TescoLabsApi</code> and then add to my cart? </p>