【发布时间】:2017-06-17 20:43:17
【问题描述】:
我正在尝试在我的网上商店项目中为购物车创建一个结帐。 我希望每次您的新闻结帐时都会从模型 Clothes.Amount 1 为您在购物车会话中拥有的每种产品。 然后我想清理购物车。
在购物车控制器中,我有这三个功能和一个要订购的功能,但我认为这对这个问题并不重要。 错误就在这行
Item.Cl.Amount--;
Delete(Item.Cl.Id);
这里是代码
private int isExisting(int id)
{
List<Item> cart = (List<Item>)Session["cart"];
for (int i = 0; i < cart.Count; i++)
{
if (cart[i].Cl.Id == id)
return i;
}return -1;
}
public ActionResult Delete(int idDelete)
{
int index = isExisting(idDelete);
List<Item> cart = (List<Item>)Session["cart"];
cart.RemoveAt(index);
Session["cart"] = cart;
return View("Order");
}
public ActionResult CheckOut(int idCheck)
{
int index = isExisting(idCheck);
if(index != -1) {
foreach (Item item in (List<Item>)Session["cart"]) {
Item.Cl.Amount--;
Delete(Item.Cl.Id);
}
}
return View();
}
【问题讨论】:
标签: c# asp.net-mvc checkout webshop