How can I open a pdf file directly in my browser?

后端 未结 7 545
陌清茗
陌清茗 2020-12-25 15:14

I would like to view a PDF file directly in my browser. I know this question is already asked but I haven\'t found a solution that works for me.

Here is

7条回答
  •  -上瘾入骨i
    2020-12-25 15:47

    Instead of returning a File, try returning a FileStreamResult

    public ActionResult GetPdf(string fileName)
    {
        var fileStream = new FileStream("~/Content/files/" + fileName, 
                                         FileMode.Open,
                                         FileAccess.Read
                                       );
        var fsResult = new FileStreamResult(fileStream, "application/pdf");
        return fsResult;
    }
    

提交回复
热议问题