Reputation: 8471
I want to try out to download pdf in the browser.
Now in my code, I followed the links and here's what I got.
Controller:
public ActionResult DownloadPdf(){
var path = Server.MapPath("~/Doc/Pdf/sample.pdf");
return File(path , "application/pdf", "sample.pdf");
}
View
<a href="#" id="download-pdf">Download PDF</a>
Javascript
$("#download-pdf").click(function() {
$.post("/Home/DownloadPdf");
return false;
});
Folder Structure:
Solution
-- Project
---- ....
---- Doc
------ Pdf
-------- sample.pdf
When I try to examine the developer's tool in chrome.
I got a 200 status and in the preview tab, I got some characters. I think it is the content of the pdf.
Now my problem is, the pdf won't show up in the browser as downloaded file.
Any help would be much appreciated. Thanks
Upvotes: 1
Views: 789
Reputation: 494
try this
< a href="/Home/DownloadPdf" id="download-pdf">Download PDF< /a>
Upvotes: 3