码迷,mamicode.com
首页 > Web开发 > 详细

MVC - File download action

时间:2015-10-18 07:45:38      阅读:251      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!