Home view a PDF without downloading it
Reply: 0

view a PDF without downloading it

user5858
1#
user5858 Published in September 19, 2018, 6:43 pm

Now my controller returns the file in this way:

[HttpGet]
public IActionResult document(int id)
{
      var byteArray = db.instances.Where(c => c.id == id).FirstOrDefault().document;    
      if (byteArray == null)
      {
            return null;
      }
      Stream stream = new MemoryStream(byteArray);

      return File(stream, "application/pdf", "document.pdf");
}

Client:

<a href="@Url.Action("document", "Catalog", new { id = Model.id })" target="_blank">Open pdf</a>

I would like to view the PDF without downloading it, how can I do it?

share|improve this question
  • 2
    Specifiying the filename parameter to File actually causes a Content-Disposition: attachment header to be set. This header actually forces download. The default behavior is to view inline. So, the key is to not specify the filename. However, bear in mind that viewing a PDF in browser is still conditional on the capabilities of the client's browser. If it doesn't support viewing PDFs natively or doesn't have a PDF-viewing plugin installed, then it will still prompt a download no matter what, and there's nothing you can do about that. – Chris Pratt Nov 13 '17 at 14:00

1 Answer 1

active oldest votes
up vote 2 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342947 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO