title: How to download an excel File and PDF file using Jquery Ajax MVC
body: <p>I am using MVC Application. I want to download excel file and PDF file using Jquery AJAX.</p>
  
  <p>In View page</p>
  
  <pre><code> &lt;a href="javascript:void(0)" class="excelbtn" data-is-pdf="false" &gt;Export To Excel&lt;/a&gt;
   &lt;a href="javascript:void(0)" class="pdfbtn" data-is-pdf="true"&gt;Export To PDF&lt;/a&gt;
  </code></pre>
  
  <p>Jquery ajax</p>
  
  <pre><code>$.ajax({
          type: 'GET',
          url: '/Report/ExportReports',
          contentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
          data: {
              Parameter1: Parameter1,
              Parameter2: Parameter2,
          },
          cache: false,
          success: function (isSuccess) {
              if (isSuccess.Success) {
                  }
              } else {
                  alert('Something went wrong. Please try again after sometime...');
              }
          },
          error: function (data, status, e) {
          }
      });
  </code></pre>
  
  <p>In Controller </p>
  
  <pre><code>public ActionResult ExportReports(string Parameter1, string Parameter2)
      {
         if (Parameter1 = "PDF")
          {
              DataTable exportData = grid.GetExportData(dataSource);
              MemoryStream pdfStream = gridData.ExportToPDF(exportData, repType);
  
              Response.ClearContent();
              Response.ClearHeaders();
              Response.ContentType = "application/pdf";
              Response.AppendHeader("Content-Disposition", "attachment; filename=" + executeRepType + ".pdf");
              Response.BinaryWrite(pdfStream.ToArray());
              Response.End();
          }
          else
          {
              DataTable exportData = grid.GetExportData(dataSource);
              MemoryStream excelStream = gridData.ExportToExcel(exportData, executeRepType);
              //Write it back to the client
              Response.ClearContent();
              Response.ClearHeaders();
              Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
              Response.AddHeader("content-disposition", "attachment;  filename=" + executeRepType + ".xlsx");
              Response.BinaryWrite(excelStream.ToArray());//.GetAsByteArray());
              Response.End();
          }
          return View();
      }
  </code></pre>
  
  <p>So in controller we are getting the all data but we are not able return into view page.</p>