【发布时间】:2011-03-01 18:17:13
【问题描述】:
而不是在浏览器窗口中显示 PNG,我希望操作结果触发文件下载对话框(您知道打开、另存为等)。我可以使用未知的内容类型使它与下面的代码一起使用,但是用户必须在文件名的末尾输入 .png。如何在不强制用户输入文件扩展名的情况下完成此行为?
public ActionResult DownloadAdTemplate(string pathCode)
{
var imgPath = Server.MapPath(service.GetTemplatePath(pathCode));
return base.File(imgPath, "application/unknown");
}
解决方案....
public ActionResult DownloadAdTemplate(string pathCode)
{
var imgPath = Server.MapPath(service.GetTemplatePath(pathCode));
Response.AddHeader("Content-Disposition", "attachment;filename=DealerAdTemplate.png");
Response.WriteFile(imgPath);
Response.End();
return null;
}
【问题讨论】:
标签: c# asp.net-mvc image download controller