ASP.NET MVC:下载Excel文件 [英] ASP.NET MVC: Downloading an excel file

查看:398
本文介绍了ASP.NET MVC:下载Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下载一个excel C#操作方法的reutrns一个FileResult,这样内提交:

I'm downloading an excel file within C# action method the reutrns a FileResult, like this:

return File(bindata, "application/octet-stream", "mytestfile.xls");

当我手动导航到上面的方法相对应的URL,然后我得到了呈现出来的文件重新presentation。该文件将无法与另存为下载 - 对话

When I manually navigate to the URL that corresponds with the above method, then I get the rendered out representation of the file. The file will not download with a Save As -dialog.

有没有办法强制下载通过保存到发生,因为 - 对话?

Is there a way to force the download to happen through Save As -dialog?

-pom -

推荐答案

我有你得到,因为你正在返回的介质类型此行为的感觉。

I have a feeling you are getting this behavior because of the media type you are returning.

试着改变媒体类型的应用程序/ vnd.ms - Excel中是这样的:

Try changing the media type to application/vnd.ms-excel like this:

return File(bindata, "application/vnd.ms-excel", "mytestfile.xls");

这篇关于ASP.NET MVC:下载Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆