I want to create a shopping cart, but i get this error. As you may see, i have the ShoppingCart class in the WebApplication1.App_Code namespace but when i try using WebApplication1.App_Code in the Default.aspx.cs, it does not work.

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");
        }

Related posts

Recent Viewed