我正在尝试发送一个9MB的.xls
文件作为web api控制器方法的响应。用户将单击页面上的按钮,这将通过浏览器触发下载。
这是我到目前为止得到的,但它不工作,但它也不会抛出任何异常。
[AcceptVerbs("GET")]
public HttpResponseMessage ExportXls()
{
try
{
byte[] excelData = m_toolsService.ExportToExcelFile();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new MemoryStream(excelData);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Data.xls"
};
return result;
}
catch (Exception ex)
{
m_logger.ErrorException("Exception exporting as excel file: ", ex);
return Request.CreateResponse(HttpStatusCode.InternalServerError);
}
}
下面是通过单击界面中的按钮来调用coffeescript/javascript jquery ajax。
$.ajax(
url: route
dataType: 'json'
type: 'GET'
success: successCallback
error: errorCallback
)
现在我想起来,也许dataType是错的,不应该是json…
https://stackoverflow.com/questions/14831860
复制相似问题