title: Mvc - store a list in session and then retrieve its value
body: <p>Hello I'm trying to make a simple online magazine and I got to the part where when the user clicks addtoCart 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 basketViewModel (class) inside my AddProductToCart method I add the product, the details for which I get from database in property of List. </p>
  
  <p>So I can't figure out this issue: Somewhere in the control I should save this list in a Session and if the user adds more products the next time I should get the list from this session. If someone can give me an example of controler with an index action that can do this I would be really thankful. </p>
  
  <pre><code>public class BasketViewModel
      {
  
          private readonly IProductLanguagesRepository prodlanRepository;
          public List&lt;Cart&gt; listProductsinBasket { get; set; }
          public BasketViewModel() : this(new ProductLanguagesRepository())
          {
  
          }
  
  
  
      public BasketViewModel(IProductLanguagesRepository prodlanRepository)
      {
          this.prodlanRepository = prodlanRepository;
      }
      public void AddProductToCart(int id,int quantity)
      {
          ProductLanguages nwProduct = prodlanRepository.GetProductDetails(id);
          if (nwProduct != null)
          {
              Cart cr = new Cart();
              cr.Product = nwProduct;
              cr.Quantity = quantity;
              listProductsinBasket.Add(cr);
  
          }
  </code></pre>