I got this issue for whole day and i still couldn't figure it out why.
public ActionResult AddToCart(string productcode, int productQty)
{
var db = new PetaPoco.Database("ProductDB");
var sql = Sql.Builder.Append("Select *");
sql.Append("from Product");
sql.Append("where Code= @0", productcode);
Product product = db.SingleOrDefault<Product>(sql);
Cart cart = GetCart();
cart.AddToCart(product, productQty);
return View(cart);
}
Here is my GetCart()
code.
public Cart GetCart()
{
Cart cart = (Cart)Session["cart"];
if (cart == null)
{
cart = new Cart();
Session["cart"] = cart;
}
return cart;
}
And here is my AddToCart(Product p, int qty)
code.
public List<Product> AddToCart(Product p, int qty)
{
if (p != null)
{
cart.Add(p);
}
return cart;
}
Error is thrown at cart.Add(p)
. Does anyone know why is it crying?