This might be a simple one but here goes:
I\'m implementing an excel downloadable report in my MVC3 application. I\'ve used this method in the past and it\'s worked
Well, FileResult
inherits from ActionResult
:
If you result can be either a RedirectToRouteResult
(inheriting from ActionResult
) or a FileResult
, then... your action must be of type ActionResult
, which can manage both.
something like that :
[HttpPost]
public ActionResult ExcelReportDownload(ReportExcelDownloadRequest reportRequest)
{
ReportEngine re = new ReportEngine();
Stream report = re.GetReport(reportRequest);
if (report == null)
return RedirectToAction();
else
return new FileStreamResult(report, "application/ms-excel")
{
FileDownloadName = "SalesReport.xls"
};
}