MVC - File download action

http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-asp-net-mvc

public ActionResult Download()
{
    var document = ...
    var cd = new System.Net.Mime.ContentDisposition
    {
        // for example foo.bak
        FileName = document.FileName, 

        // always prompt the user for downloading, set to true if you want 
        // the browser to try to show the file inline
        Inline = false, 
    };
    Response.AppendHeader("Content-Disposition", cd.ToString());
    return File(document.Data, document.ContentType);
}


and Remember to use news {target="_blank"} in ActionLink parameter

你可能感兴趣的:(MVC - File download action)