Assefa Tedla
Assefa Tedla

Reputation: 103

Error While trying to view PDF document in browser it just get downloaded [ASP.net Core 3.0]

I have tried to view pdf documents in my ASP.net core application but when I clicked on Read button the pdf document just get downloaded Here is My Code In my Home Controller I have GetPdf Action

  public ActionResult GetPdf(string fileName)
        {
            string filePath = "~/file/" + fileName;
            Response.Headers.Add("Content-Disposition", "inline; filename=" + fileName);
            return File(filePath, "application/pdf");
        }

and in the View part I have used

 <a href="/Home/GetPdf/php.pdf" class="btn btn-default">Read</a>

Upvotes: 2

Views: 166

Answers (2)

Abdulhakim Zeinu
Abdulhakim Zeinu

Reputation: 3829

Turn off any download manager software installed on your system. When you try to read the pdf the download manager will take it over to download it.

Upvotes: 1

bsod_
bsod_

Reputation: 941

Change your ActionMethod to this -

  public ActionResult GetPdf(string fileName)
        {
            string filePath = "~/file/" + fileName;
            Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);
            return File(filePath, "application/pdf");
        }

Note the change of Response.Headers.Add to Response.AddHeader

Upvotes: 0

Related Questions