title: How create view for show cookie's info in asp.net mvc using razor?
body: <p>I'm developing  an online store using <code>asp.net mvc 5</code> and I used <code>cookie</code> for add goods to cart . I want to have a page to show selected items (in cookie) and I don't know how do it, I just wrote an action result for it named <code>Basket</code> . I should use <code>@model List&lt;BasketVM&gt;</code> in my view but when don't know how ?!</p>
  
  <p>could anyone help me please ?
  Thanks</p>
  
  <p><strong>GoodController</strong></p>
  
  <pre><code>[HttpGet]
      public ActionResult Basket()
      {
          GoodDetailsRepositories blGoodDetails = new GoodDetailsRepositories();
          List&lt;BasketVM&gt; listBasket = new List&lt;BasketVM&gt;();
          List&lt;HttpCookie&gt; lst = new List&lt;HttpCookie&gt;();
          for (int i = Request.Cookies.Count - 1; i &gt;= 0; i--)
          {
              if (lst.Where(p =&gt; p.Name == Request.Cookies[i].Name).Any() == false)
                  lst.Add(Request.Cookies[i]);
          }
          foreach (var item in lst.Where(p =&gt; p.Name.StartsWith("NishtmanCart_")))
          {
              listBasket.Add(new BasketVM {
                  GoodDetails = blGoodDetails.Find(Convert.ToInt32(item.Name.Substring(13))), Count =Convert.ToInt32(item.Value) });
          }
          return View(listBasket);
      }
  </code></pre>
  
  <p><strong>BasketVM.cs</strong></p>
  
  <pre><code> public class BasketVM
  {
      public NP1.Models.GoodDetail GoodDetails { get; set; }
      public int Count { get; set; }
  }
  </code></pre>
  
  <p><strong>GoodDetails.cs</strong></p>
  
  <pre><code>public partial class GoodDetail
  {
      public GoodDetail()
      {
          this.FactorItems = new HashSet&lt;FactorItem&gt;();
      }
  
      public int DetailsGoodID { get; set; }
      public int FKSubGoods { get; set; }
      public string NishtmanCode { get; set; }
      public string DetailsColor { get; set; }
      public string DetailsExist { get; set; }
      public long DetailsNowPrice { get; set; }
      public Nullable&lt;long&gt; DetailsPrePrice { get; set; }
      public string DetailsName { get; set; }
      public string DetailsLeatherType { get; set; }
      public string DetailsWeight { get; set; }
      public string DetailsSize { get; set; }
      public string DetailsProducer { get; set; }
      public string DetailsExtraInfo { get; set; }
      public string DetailsURL { get; set; }
      public string DetailsKeyWords { get; set; }
      public string DetailsTags { get; set; }
      public int DetailsLike { get; set; }
      public int DetailsDisLike { get; set; }
      public string DetailsImage1 { get; set; }
      public string DetailsSmallImage1 { get; set; }
      public string DetailsImage2 { get; set; }
      public string DetailsSmallImage2 { get; set; }
      public string DetailsImage3 { get; set; }
      public string DetailsSmallImage3 { get; set; }
      public string DetailsImage4 { get; set; }
      public string DetailsSmallImage4 { get; set; }
  
      public virtual SubGood SubGood { get; set; }
      public virtual ICollection&lt;FactorItem&gt; FactorItems { get; set; }
  }
  </code></pre>
  
  <p><strong>Add to cart code</strong> </p>
  
  <pre><code>public ActionResult AddToCart (int Id , int Count)
      {
          try
          {
              if (Request.Cookies.AllKeys.Contains("NishtmanCart_" + Id.ToString()))
          {
              //Edit cookie
              var cookie = new HttpCookie("NishtmanCart_" + Id.ToString(), (Convert.ToInt32(Request.Cookies["NishtmanCart_" + Id.ToString()].Value) + 1).ToString());
              cookie.Expires = DateTime.Now.AddMonths(1);
              cookie.HttpOnly = true;
              Response.Cookies.Set(cookie);
  
          }
          else
          {
              //Add new cookie
              var cookie = new HttpCookie("NishtmanCart_" + Id.ToString(), Count.ToString());
              cookie.Expires = DateTime.Now.AddMonths(1);
              cookie.HttpOnly = true;
              Response.Cookies.Add(cookie);
          }
              List&lt;HttpCookie&gt; lst = new List&lt;HttpCookie&gt;();
              for (int i = 0; i &lt; Request.Cookies.Count; i++ )
              {
                  lst.Add(Request.Cookies[i]);
              }
  
              bool isGet = Request.HttpMethod == "GET";
              int CartCount = lst.Where(p =&gt; p.Name.StartsWith("NishtmanCart_") &amp;&amp; p.HttpOnly != isGet).Count();
              return Json(new MyJsonData()
              {
                  Success = true,
                  Script = MessageBox.Show("Good added successfully", MessageType.Success).Script,
  
                  Html = "cart items (" + CartCount.ToString() + ")"
              }
                  );
          }
          catch(Exception)
          {
              return Json(new MyJsonData()
              {
                  Success = false,
  
                  Script = "alert('Good didn't add');",
                  Html = ""
              }
                  );
  
          }
  
      }
  </code></pre>