PDF force download as opposed to open in browser

asp.net, asp.net-mvc, asp.net-mvc-4, c#, razorpdf

Solution

Try adding the `content-disposition` header before returning the `PDFResult` object.

public PdfResult Pdf()
{
  Response.AddHeader("content-disposition", "attachment; filename=YourSanitazedFileName.pdf");

  // With no Model and default view name.  Pdf is always the default view name
  return new PdfResult();
}

Problem

I am using RazorPDF and I would like to force download the PDF as opposed to open in browser tab. How do I do this? Thanks ``` public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(string Id) { return RedirectToAction("Pdf"); } public PdfResult Pdf() { // With no Model and default view name. Pdf is always the default view name return new PdfResult(); } ```

Original source

Related problems