假设你有一个ShoppingCart对象叫Cart.
在购物页面
if(Session["Cart"]!=null) Session["Cart"] = Cart;
else
{
ShoppingCart cart = Session["Cart"] as ShoppingCart ;
cart.Add("Some Goods");
}在订单网页if(Session["Cart"]!=null)
{
ShoppingCart cart = Session["Cart"] as ShoppingCart ;
//将购物车的物品绑定到页面中的物品列表
}
在购物页面
if(Session["Cart"]!=null) Session["Cart"] = Cart;
else
{
ShoppingCart cart = Session["Cart"] as ShoppingCart ;
cart.Add("Some Goods");
}在订单网页if(Session["Cart"]!=null)
{
ShoppingCart cart = Session["Cart"] as ShoppingCart ;
//将购物车的物品绑定到页面中的物品列表
}
-- != 改为 ==
if(Session["Cart"] == null) Session["Cart"] = Cart;
而且可以用 cookie 保存 “订单”