Redirecting to MVC ActionResult from FileResult

前端 未结 1 953
后悔当初
后悔当初 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();
            else
               return new FileStreamResult(report, "application/ms-excel")
               {
                   FileDownloadName = "SalesReport.xls"
               };
        }
    

    0 讨论(0)
提交回复
热议问题