Here is the important part, called from an AJAX call in the view:
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add(fileName);
ws.Cells["A1"].LoadFromDataTable(dt, true);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xlsx");
Byte[] bytes = pck.GetAsByteArray();
Response.BinaryWrite(bytes);
Response.End();
}
But it creates an error:
Any idea what is wrong?