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