在链接上单击MVC剃须刀中的SaveFile对话框 [英] SaveFile dialog in MVC razor on link click

查看:76
本文介绍了在链接上单击MVC剃须刀中的SaveFile对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下,如何在mvc razor4中打开保存文件对话框? 我想使用普通的保存文件对话框,但是我发现它只能在Win窗体中使用.所以我在谷歌搜索,但没有找到好的解决方案.只有那里

I would like to ask, how can I open savefile dialog in mvc razor4? I wanted use normal savefile dialog but I have found out that it can be used only in Win forms. So I search in google but didn't find good solution. Only that there is

<input type="file" /> 

但是我认为覆盖他的表情是有问题的.

but I think it is problematic to overwrite his look.

我有这样的东西:

<a href="@Url.Action("ExcelExport","Home")"><img src="@Url.Content("~/images/excel_icon.png")" id="excel-export-img" /></a>

单击该按钮后,我想显示保存文件"对话框. 知道关于它的一些材料或如何做的人吗?

I want to display Savefile dialog after click to that. Know anyone about some materials about it or how to do it?

打个招呼.

推荐答案

请记住,HTTP不一定具有文件"的概念.它具有请求和响应.每个都有标题和内容.因此,您想要的是返回带有标头的文件内容,该标头指示该文件是文件",应这样处理.当然,仍然要由浏览器决定如何处理它.

Keep in mind that HTTP doesn't necessarily have a concept of "files." It has requests and responses. And each of those has headers and content. So what you want is to return the contents of a file with a header indicating that it is a "file" and should be treated as such. It's still up to the browser how to actually handle it, of course.

在ASP.NET MVC中执行此操作的方法是通过控制器操作返回File() .像这样:

The way to do this in ASP.NET MVC is to return a File() from your controller action. Something like this:

return File("SomeFile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

当然,File()方法有几个重载,其中一些重载接受字节数组或流,而不是实际服务器端文件的名称.

There are, of course, several overloads for the File() method, some of which accept a byte array or stream instead of the name of an actual server-side file.

这篇关于在链接上单击MVC剃须刀中的SaveFile对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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