public IActionResult Product(ProductLocationViewModel p) { if (ModelState.IsValid) { ProductLocationViewModel model = new ProductLocationViewModel(); Product prod = _repository.GetProductFromId(p.ProductId); model.ProductId = prod.ProductId; model.ProductName = prod.ProductName; model.ProductPrice = prod.ProductPrice; model.ProductImage = prod.ProductImage; model.locations = _repository.GetLocations().ToList(); var user_id = HttpContext.Request.Cookies["user_id"]; Product item = new Product(p.ProductId, p.ProductName, p.ProductPrice, p.ProductQty, p.ProductImage); _repository.AddItemToCart(item, Int32.Parse(user_id), p.LocationId); TempData["Success"] = "1"; TempData.Keep("Success"); return(View(model)); } ModelState.AddModelError("", "Error adding item to cart"); return(View(p)); }