title: Store List of objects in Session variable
body: <p>I want to store the result of the query called by the controller in a variable</p>
  
  <pre><code>  public ActionResult Index()
      {
          Session["dateDebut"] = DateTime.Now.AddMonths(-1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
          Session["dateFin"] = DateTime.Now.AddDays(0).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
          HostClassReq hostClassChart = new HostClassReq();
          Chart_Event cex = new Chart_Event();
  
          var viewModel = new Chart_Event
          {
              chartVM = hostClassChart.callHostClass()
          };
  
          return View(viewModel);
      }
  </code></pre>
  
  <p>Here is the methode callHostClass implementation </p>
  
  <pre><code>    public Highcharts callHostClass()
      {
          DateTime begin = DateTime.ParseExact(HttpContext.Current.Session["dateDebut"].ToString(), "dd/MM/yyyy",
                                       System.Globalization.CultureInfo.InvariantCulture);
          DateTime end = DateTime.ParseExact(HttpContext.Current.Session["dateFin"].ToString(), "dd/MM/yyyy",
                                     System.Globalization.CultureInfo.InvariantCulture).AddDays(1);
          CreateChart createChart = new CreateChart();
          List&lt;String&gt; xs = new List&lt;string&gt;();
  
  
  
  
  
          var maListe = (from p in db.exclure
                        where (p.type.Contains("Host Class"))
                        group p by p.libelle into g
                        select new
                        {
                            libellex = g.Key
                        }).ToList();
  
          List&lt;string&gt; strListe = new List&lt;string&gt;();
  
          foreach (var x in maListe.Select(i =&gt; i.libellex))
          {
  
              strListe.Add(x.ToString());
          }
  
  
  
             var   myList = (from p in db.Full
                        where ( (p.date_reception &gt; begin &amp; p.date_reception &lt; end &amp; !p.mc_host_class.Contains("NULL")) &amp;
  
                     (!strListe.Contains(p.mc_host_class)))
                        group p by p.mc_host_class into g
                        orderby g.Count() descending
                        select new
                        {
                            hostclassx = g.Key,
                            countx = g.Count()
                        }).Take(10).ToList();
  
  
  
         //  HttpContext.Current.Session["allList"] = myList;
           List&lt;Full&gt; questions = (List&lt;Full&gt;)HttpContext.Current.Session["allList"];
  
         //  questions = List &lt;Full&gt; myList;
           foreach (var x in questions)
           {
  
           }
  
  
  
           object[] ys =  myList.Select(a =&gt; (object)a.countx.ToString()).ToArray();
  
  
  
  
  
  
          foreach (var x in myList.Select(i =&gt; i.hostclassx))
          {
              if (x.Length &gt; 20)
              {
                  xs.Add((x.Substring(0, 20)));
              }
              else
              {
                  xs.Add(x);
              }
  
          }
  
  
  
          var chart = createChart.createChartBar(xs, ys, 10);
  
          return chart;
  
  
      }
  </code></pre>
  
  <p>I need to store the result of myList query in a variable that will be accessed by another classes i need some help.</p>