首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载xlsx作为httpresponsemessage

下载xlsx作为httpresponsemessage
EN

Stack Overflow用户
提问于 2016-12-07 10:23:09
回答 1查看 530关注 0票数 0

我正在尝试下载一个要封装为httpresponsemessage的xlsx扩展文件。该文件不会显示为下载,但是chrome中的XHR请求似乎包含数据。

代码语言:javascript
复制
public HttpResponseMessage GetExcelFile(string csvdata)
{
      var result = new HttpResponseMessage(HttpStatusCode.OK);

     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     MemoryStream memStream = new MemoryStream(encoding.GetBytes(csvdata));

      result.Content = new ByteArrayContent(encoding.GetBytes(csvdata));

      result.Content.Headers.ContentType = new    MediaTypeHeaderValue("application/octet-stream");

       result.Content.Headers.ContentDisposition = new        ContentDispositionHeaderValue("attachment"); 

       result.Content.Headers.ContentDisposition.FileName = "Data.xlsx";

       return result;

}

这是将httpresponsemessage抛入angularjs UI的api调用。有什么建议可以让它工作吗?

EN

回答 1

Stack Overflow用户

发布于 2016-12-08 00:11:35

希望您使用web API get方法在ValuesController.cs类中返回HttpResponseMessage。( // GET: api/Values)

假设在单击按钮时触发ng- click,将ng-click="TakeIT()"作为属性添加到按钮元素中。

在你的角度控制器中,将函数绑定到$scope as,

代码语言:javascript
复制
$scope.TakeIT= function () {                        
                    window.location = 'api/Values';
                };

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41008376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档