blackik
blackik

Reputation: 495

Save file dialog in MVC

How to create save file dialog in MVC application? I couldn't find any example.

Thanks in advance.

Upvotes: 4

Views: 9600

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

By using the Content-Disposition header to attachment when returning the file to download:

public ActionResult Download()
{
    return File(@"c:\work\report.pdf", "application/pdf", "reoprt.pdf");
}

Or if the file to download is dynamically generated:

public ActionResult Download()
{
    byte[] pdf = ... get the contents of the report
    return File(pdf, "application/pdf", "reoprt.pdf");
}

Upvotes: 7

Related Questions