Reputation: 103
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
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
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