Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 结账车MVC_C#_Asp.net Mvc_Checkout_Webshop - Fatal编程技术网

C# 结账车MVC

C# 结账车MVC,c#,asp.net-mvc,checkout,webshop,C#,Asp.net Mvc,Checkout,Webshop,我正在尝试在我的webshop classe项目中为购物车创建一个签出。 我想,每次你的新闻结帐,它将采取从模型衣服。金额1为每个产品,你在购物车会话。 然后我想清洁购物车 在cart controller中,我有这三个功能,另外一个功能需要订购,但我认为这对于这个问题并不重要。 此行中的错误为int Item.Cl.Amount--; Delete(Item.Cl.Id); 这是密码 private int isExisting(int id) { L

我正在尝试在我的webshop classe项目中为购物车创建一个签出。 我想,每次你的新闻结帐,它将采取从模型衣服。金额1为每个产品,你在购物车会话。 然后我想清洁购物车

在cart controller中,我有这三个功能,另外一个功能需要订购,但我认为这对于这个问题并不重要。 此行中的错误为int

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();
        }
private int存在(int id)
{
列表购物车=(列表)会话[“购物车”];
for(int i=0;i
从您的问题中,我看不出您遇到了什么错误。但只要看看您的代码,我就会认为这是经典的“集合已修改;枚举操作可能无法执行”

在方法
CheckOut
中,您在会话中迭代项目列表。在执行此操作时,可以调用
Delete
方法,从列表中删除项目。这是绝对不允许的

如果这是您的问题,您可以将第二种方法更改为以下方法:

public ActionResult CheckOut(int idCheck)
        {
            int index = isExisting(idCheck);
            if(index != -1) { 
                foreach (Item item in ((List<Item>)Session["cart"]).ToList()) {
                    Item.Cl.Amount--;
                    Delete(Item.Cl.Id);
                }
            }
            return View();
        }
公共操作结果签出(int-idCheck)
{
int index=isExisting(idCheck);
如果(索引!=-1){
foreach(在((列表)会话[“购物车”]).ToList()中的项目{
第1.Cl.项金额--;
删除(第1.1.1项);
}
}
返回视图();
}