In WebForms, I would normally have code like this to let the browser present a "Download File" popup with an arbitrary file type, like a PDF, and a filename:
Response.Clear() Response.ClearHeaders() ''# Send the file to the output stream Response.Buffer = True Response.AddHeader("Content-Length", pdfData.Length.ToString()) Response.AddHeader("Content-Disposition", "attachment; filename= " & Server.HtmlEncode(filename)) ''# Set the output stream to the correct content type (PDF). Response.ContentType = "application/pdf" ''# Output the file Response.BinaryWrite(pdfData) ''# Flushing the Response to display the serialized data ''# to the client browser. Response.Flush() Response.End()
How do I accomplish the same task in ASP.NET MVC?