title: Why my session in the view control is null
body: <p>Hello I'm trying to make a simple online magazine and I get to the part where when the user clicks <code>addtoCart</code> button</p>
  
  <p>My model Cart holds two properties - Product and Quantity</p>
  
  <pre><code>public class Cart
  {
  
   public ProductLanguages Product { get; set; }
          public int Quantity { get; set; }
  
  }
  </code></pre>
  
  <p>So in my <code>basketViewModel</code> in my <code>AddProductToCart</code> method, I add the product with details I get from database in property of type List. Then I save this list in a session.
  And if, for example, the user clicks 'continue to shop' button and returns to index page -  next time when he presses 'addtocart' for the new product as you see I make this check          </p>
  
  <pre><code>lstCarts = (List&lt;Cart&gt;)HttpContext.Current.Session["Cart"];
          if (lstCarts==null)
          {
             lstCarts = new List&lt;Cart&gt;();
          }
  </code></pre>
  
  <p>First, I try to get the list from session so i can get previously saved products.
  But my session is always null so i always lose my previously purchased products. The curious thing is that I'm sure that I saved the list of products in this line </p>
  
  <pre><code>        HttpContext.Current.Session["Cart"] = lstCarts;
  </code></pre>
  
  <p>Here is my viewmodel</p>
  
  <pre><code> public class BasketViewModel
      {
      private readonly IProductLanguagesRepository prodlanRepository;
      public List&lt;Cart&gt; lstCarts { get; set; }
      public BasketViewModel() : this(new ProductLanguagesRepository())
      {
  
      }
  
      public BasketViewModel(IProductLanguagesRepository prodlanRepository)
      {
          this.prodlanRepository = prodlanRepository;
      }
      public void CreateCart(int id,int quantity)
      {
          lstCarts = (List&lt;Cart&gt;)HttpContext.Current.Session["Cart"];
          if (lstCarts==null)
          {
             lstCarts = new List&lt;Cart&gt;();
          }
          ProductLanguages nwProduct = prodlanRepository.GetProductDetails(id);
          if (nwProduct != null)
          {
              Cart cr = new Cart();
              cr.Product = nwProduct;
              cr.Quantity = quantity;
              lstCarts.Add(cr);
              HttpContext.Current.Session["Cart"] = lstCarts;
          }
      }      
  }
  </code></pre>
  
  <p>And my Controller</p>
  
  <pre><code> public class BasketManagementController : Controller
      {
      public ActionResult Index(int id, int quantity)
              {
                  BasketViewModel vm = new BasketViewModel();
                  vm.CreateCart(id, quantity);
                  return View(vm);
              }
       }
  </code></pre>