title: Blazor export to excel
body: <p>I am attempting to add an export to excel button on my blazor server side app. So far after combing the internet this is what I have done.</p>
  
  <p>My button</p>
  
  <pre><code>    &lt;div class="row text-right"&gt;
                  &lt;div class="col-12 p-3"&gt;
                      &lt;button class="btn btn-outline-success" @onclick="@(() =&gt;DownloadExcel(formValues.Region, formValues.startDate, formValues.endDate))"&gt;
                          Export to Excel&amp;nbsp;
                          &lt;i class="fa fa-file-excel" aria-hidden="true"&gt;&lt;/i&gt;
                      &lt;/button&gt;
                 &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>My method in my .razor page</p>
  
  <pre><code>    public FileResult DownloadExcel(string Region, DateTime StartDate, DateTime EndDate)
      {
          FileResult ExcelFile = searchService.ExportToExcel(Region, StartDate, EndDate);
          return ExcelFile;
      }
  </code></pre>
  
  <p>And Finally my logic in my service</p>
  
  <pre><code>        public FileResult ExportToExcel(string Region, DateTime StartDate, DateTime EndDate)
          {
              var queryable = context.AuditCardPinrecords.Where(s =&gt; Region == s.RegionRecordId)
                  .Where(s =&gt; s.AuditComplete == true)
                  .Where(s =&gt; s.DateTime &gt;= StartDate &amp;&amp; s.DateTime &lt;= EndDate).AsQueryable();
  
              var stream = new MemoryStream();
  
              using (var package = new ExcelPackage(stream))
              {
                  var workSheet = package.Workbook.Worksheets.Add("Sheet1");
                  workSheet.Cells.LoadFromCollection(queryable, true);
                  package.Save();
              }
  
  
              string excelName = $"AuditPinRecords-{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx";
  
              return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName); 
  
          }
  </code></pre>
  
  <p>My expected result is to download the excel file. Unfortunately nothing happens on button click. Any advice would be greatly appreciated. Thanks!</p>