List<ShoppingCartView> removeitem = (List<ShoppingCartView>)Session["ShoppingView"];
我想在点击该特定产品时删除一行。例如,如果我单击产品xxx并想要从Session [“ShoppingView”]中删除产品xxx,则列表的其余部分应保持不变。
答案 0 :(得分:2)
您可以使用Remove
Session["ShoppingView"] = (List<ShoppingCartView>)Session["ShoppingView"].Remove((List<ShoppingCartView>)Session["ShoppingView"].Where(x => x.id== sessionItemToRemove).ToList());
答案 1 :(得分:2)
你必须相应地编辑条件
var list = (List<ShoppingCartView>)Session["ShoppingView"];
Session["ShoppingView"] = list.Where(x => x.ProductName!= "pname").ToList();
答案 2 :(得分:0)
你可以这样做
List<string> foo = Session["ShoppingView"];
foo.Remove("xxx");
Session["ShoppingView"] = foo;