Set Page Title for a PDF inside the Action
Asked Answered
L

0

6

I have an action that displays a pdf

public ActionResult MyPdf()
{
    var response = pdfService.MyPdf(new PdfRequest() { SiteId = siteSession.ActiveSiteId });

    return File(response.Pdf, "application/pdf");
}

The service opens a PDF, fills out the form using data from the database, and then passes back a container class. response.Pdf is a byte[].

What I want to do is set the page title used by the browser when the PDF is opened. Currently, File(response.Pdf, "application/pdf"); will allow my browser (chrome) to display the pdf.

If I change it to File(response.Pdf, "application/pdf", "My PDF File Name");, the pdf is not displayed but is automatically downloaded.

My action has no View defined. How can I show the PDF in the browser without forcing the download and set the page title from my action method?

Lawrenson answered 3/8, 2011 at 17:25 Comment(4)
I'm not really familiar with mvc, but to get the pdf to display in the browser and specify a filename you usually set the content disposition header to inline (#1395651). Is File your own type or is it included in the framework?Gurule
It is included in the framework.Lawrenson
Sorry, if you don't mind could you give me the fully qualified name. I'm looking for it but I can't find it (maybe because I have MVC3 installed and not MVC2)?Gurule
FileContentResultLawrenson

© 2022 - 2024 — McMap. All rights reserved.