public ActionResult AddItemsToCart(int productid) { using (RHASTOREEntities db = new RHASTOREEntities()) { if (User.Identity.Name == "") { return(RedirectToAction("Login", "Account")); } else { var currentuser_id = Convert.ToInt32(User.Identity.Name);//this is actually the unique user id,the name is misleading var product_id = productid; var quantity = 1; Cart c = new Cart(); c.userid = currentuser_id; c.ProductId = product_id; c.Quantity = quantity; db.Carts.Add(c); db.SaveChanges(); } return(RedirectToAction("Index")); } }