我想创建一个购物车,但出现此错误。如您所见,我在 WebApplication1.App_Code 命名空间中有 ShoppingCart 类,但是当我尝试在 Default.aspx.cs 中使用 WebApplication1.App_Code 时,它不起作用。
namespace WebApplication1.App_Code
{
public class ShoppingCart
{
public List<CartItem> Items { get; private set; }
public static readonly ShoppingCart Instance;
static ShoppingCart()
{
if (HttpContext.Current.Session["ShoppingCart"] == null)
{
Instance = new ShoppingCart();
Instance.Items = new List<CartItem>();
HttpContext.Current.Session["ShoppingCart"] = Instance;
}
else
{
Instance = (ShoppingCart)HttpContext.Current.Session["ShoppingCart"];
}
}
using System;
using System.Data;
using System.Linq;
using WebApplication1.App_Code;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddShoes_Click(object sender, EventArgs e)
{
ShoppingCart.Instance.AddItem(1);
Response.Redirect("ViewCart.aspx");
}