ASP.NET MVC 4 FileResult - In error

后端 未结 4 1629
我寻月下人不归
我寻月下人不归 2021-02-19 20:35

I have a simple Action on a controller which returns a PDF.

Works fine.

public FileResult GetReport(string id)
{
    byte[] fileBytes = _manager.GetRepor         


        
4条回答
  •  自闭症患者
    2021-02-19 21:21

    I would change the return type of your method to ActionResult.

    public ActionResult GetReport(string id)
    {
        byte[] fileBytes = _manager.GetReport(id);
        if (fileBytes != null && fileBytes.Any()){
            string fileName = id+ ".pdf";
            return File(fileBytes, MediaTypeNames.Application.Octet, fileName);
        }
        else {
            //do whatever you want here
            return RedirectToAction("GetReportError");
        }
    }
    

提交回复
热议问题