Redirecting to MVC ActionResult from FileResult

前端 未结 1 958
后悔当初
后悔当初 2020-12-10 02:47

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

相关标签:
1条回答
  • 2020-12-10 03:13

    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(<action Name>);
            else
               return new FileStreamResult(report, "application/ms-excel")
               {
                   FileDownloadName = "SalesReport.xls"
               };
        }
    
    0 讨论(0)
提交回复
热议问题