我的Asp Web Api控制器中有以下代码
public HttpResponseMessage Download(RequestModel model)
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
string dataPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data");
AttachmentsHelper attachmentsHelper = new AttachmentsHelper(model, dataPath);
string attachmentsFile = attachmentsHelper.GetAttachments();
response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(attachmentsFile, FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "photos";
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(MediaTypeNames.Application.Octet);
return response;
}
当我通过Ajax请求此方法时,我得到的结果在我的FireBug中看起来很奇怪
如何强制浏览器开始下载返回的文件?