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?

Josh
  • 16,286
  • 25
  • 113
  • 158
  • 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 (http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment). Is `File` your own type or is it included in the framework? – rsbarro Aug 03 '11 at 18:04
  • It is included in the framework. – Josh Aug 04 '11 at 13:48
  • 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)? – rsbarro Aug 04 '11 at 14:38
  • [`FileContentResult`](http://msdn.microsoft.com/en-us/library/system.web.mvc.filecontentresult.aspx) – Josh Aug 08 '11 at 15:24

0 Answers0