首页 > Web开发 > 详细

MVC - File download action

时间:2015-10-18 07:45:26      阅读:250      评论:0      收藏:0      [点我收藏+]

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

原文:http://blog.csdn.net/jameszhou/article/details/49225309

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!