title: Pass data between Actions in MVC
body: <p>I have a mvc web application which contains chart and table data. </p>
  
  <p><strong>Scenario:</strong></p>
  
  <p>I am populating data in the Index method and return the model to view for binding. In view, table bind with the data. I also want to bind the chart with same data. Chart bind with child action. I set TempData[] object in the Index method and retrieve the same in Chart action. </p>
  
  <p><strong>Code:</strong></p>
  
  <p><em>Controller</em></p>
  
  <pre><code>        public ActionResult Index()
      {
          var data = new List&lt;MyModel&gt;()
          {
              new MyModel { Text = "Name1", Value = 123 },
              new MyModel { Text = "Name2", Value = 24 },
          };
          TempData["data"] = data;
          return View(data);
      }
  
      public FileContentResult Chart()
      {
          List&lt;MyModel&gt; data = TempData["data"] as List&lt;MyModel&gt;;
          var chart = new Chart
          {
              Width = 300,
              Height = 450,
         };
          if (data != null)
          {
              chart.ChartAreas.Add("");
              chart.Series.Add("");
              chart.Series[0].ChartType = SeriesChartType.Column;
              foreach (var q in data)
              {
                  chart.Series[0].Points.AddXY(q.Text, Convert.ToDouble(q.Value));
              }
          }
          using (var chartimage = new MemoryStream())
          {
              chart.SaveImage(chartimage, ChartImageFormat.Png);
              return File(chartimage.GetBuffer(), @"image/png");
          }
      }
  
      public async Task&lt;ActionResult&gt; Export()
      {
          var converter = new HtmlToPdf();
          var baseAddress = new Uri("http://localhost:4545/");
          var cookieContainer = new System.Net.CookieContainer();
  
          using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
          using (HttpClient client = new HttpClient(handler) { BaseAddress = baseAddress })
          {
              var result = await client.GetAsync("/Home/Index");
              var htmlString = await result.Content.ReadAsStringAsync();
  
              var doc = converter.ConvertHtmlString(htmlString, baseAddress.ToString());
              doc.Save(System.Web.HttpContext.Current.Response, true, "test.pdf");
              doc.Close();
          }
          return null;
      }
  </code></pre>
  
  <p><em>View:</em></p>
  
  <pre><code>&lt;div class="row"&gt;
  @using (Html.BeginForm("Index", "Home", FormMethod.Get))
  {
  &lt;div class="col-md-12"&gt;
      &lt;table&gt;
          @{
              foreach (var item in Model)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          @item.Text
                      &lt;/td&gt;
                      &lt;td&gt;
                          @item.Value
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  }
          }
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;div class="col-md-12"&gt;
      &lt;img src="@Url.Action("Chart")" /&gt;
      &lt;input type="submit" value="Filter" /&gt;
  &lt;/div&gt;
  }
  &lt;div class="col-md-12"&gt;
      @using (Html.BeginForm("Export", "Home", FormMethod.Post))
      {
          &lt;input type="submit" value="Export" /&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Problem:</strong></p>
  
  <p>Here i am using SelectPdf to export the web page to pdf. When i click Export button, it takes the content of web page so that again Index and Chart rendered. But here i didn't get tempdata[] values. It shows as null. So chart data not getting in pdf</p>
  
  <p>Please help me to solve this issue </p>