【发布时间】:2014-11-08 17:43:18
【问题描述】:
我希望能够从我的网站下载附件,(我需要让它在 IE 中运行) 所以在html中我有:
<a href="api/attachments/DownloaAttachment?id={{attachment.Id}}" target="_blank">
Download Image
</a>
<!-- {{attachment.Id}} - it's because I use AngularJS :) -->
在控制器中:
[HttpGet]
public FileContentResult DownloaAttachment(int id)
{
var att = GetAttachmentById(id);
byte[] fileBytes = att.Content.Content;
var response = new FileContentResult(fileBytes, MediaTypeNames.Application.Octet);
response.FileDownloadName = att.FileName;
return response;
}
但是当我点击“下载图像”时 - 我有一个新窗口并从控制器响应为 json,例如:
{"FileContents":"/9j/4.. some bytes..ZK9k=","ContentType":"application/octet-stream","FileDownloadName":"Cover.jpg"}
但我不需要那个 JSON,我需要能够将附件作为文件下载到用户的计算机。 我怎样才能使它成为简单的文件下载?我做错了什么?
【问题讨论】:
标签: javascript asp.net asp.net-mvc json