【发布时间】:2017-02-21 18:26:06
【问题描述】:
我找到了这个链接。 ASP.NET MVC download image rather than display in browser
我尝试了所有方法,我的操作方法将文件转储到视图中,而不是下载。我希望能够单独下载该文件。谢谢
if (extension.ToLower() == ".docx")
{ // Handle *.jpg and
contentType = "application/docx";
}
else if (extension.ToLower() == ".jpg")
{// Handle *.gif
contentType = "image/jpeg jpeg jpg jpe";
}
else if (extension.ToLower() == ".pdf")
{// Handle *.pdf
contentType = "application/pdf";
}
Response.ContentType = contentType; // "application/force-download";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.WriteFile(FilePath );
Response.Flush();
Response.End();[![View after clicking download button][1]][1]
【问题讨论】:
-
尝试使用
application/octet-streammime 类型,看看浏览器是否为您提供了保存而不是显示的选项 -
我做到了。它仍然表现相同。
-
响应头是什么样的?
标签: asp.net-mvc