tags:

views:

92

answers:

2

I have an asp.net MVC application that calls another service to generate a pdf. I want the user to be able to click a link in my View and get a 'save as...' dialog from the browser to save the pdf.

The call to the 3rd party service is made in a Model using WebClient.

How to get I the data from the WebClient call up to View and out to the browser so it can be saved?

+3  A: 

Try this out

Response.AddHeader("content-disposition", fileName);    
Response.ContentType = "application/pdf";
Response.BinaryWrite(byteArray);

And of course the bytearray comes from the WebRequest you need to make to get the file

Dan Frade
+3  A: 

Even better, use one of our file helpers.

public ActionResult ShowPdf() { byte[] byteArray = GetBytes(); return File(byteArray, "application/pdf"); }

Haacked