public ActionResult ExportToExcel() { // Read session for filterstring .To get same table result on index when export is clicked. var filterStr = HttpContext.Session.GetString("FilterStr"); var stream = ExcelCreator.CreateExcelFileStream(_service.GetProductsByFilter(filterStr).Result.Select(p => new { p.Code, p.Name, p.Price })); var responseStream = new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"Export.xlsx" }; return(responseStream); }