如何显示打开/保存对话框ASP净MVC 4 [英] How to display open/save dialog asp net mvc 4
本文介绍了如何显示打开/保存对话框ASP净MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够请求文件,也有它返回。
我不知道如何显示一个打开/保存对话框。
查看:
函数saveDocument(){
$阿贾克斯({
网址:'/ Operacao / saveDocument',
输入:POST,
数据类型:HTML,
成功:功能(数据){
//我在这里得到的文件内容
}
});
}
控制器:
公共无效saveDocument(){
Response.ContentType =图像/ JPEG;
Response.AppendHeader(内容处置,附件;文件名= SailBig.jpg);
Response.TransmitFile(使用Server.Mappath(〜/ MyPDFs / Pdf1.pdf));
到Response.End();
}
解决方案
我认为你不能下载浏览器异步文件,只需将用户重定向到的动作和浏览器会打开一个保存对话框窗口。在asp.net mvc的,你可以有一个动作方法下载造成的 FileResult
与文件
方法的文件基本控制器。
公众的ActionResult SaveDocument()
{
字符串文件路径=使用Server.Mappath(〜/ MyPDFs / Pdf1.pdf);
字符串的contentType =应用程序/ PDF //参数到文件中
// 1。在文件服务器上的文件路径
// 2。内容类型的MIME类型
// 3。该文件的参数保存由浏览器 返回文件(文件路径,则contentType,Report.pdf);
}
I am able to request a file and also have it returned. I don´t know how to display a open/save dialog box.
View:
function saveDocument() {
$.ajax({
url: '/Operacao/saveDocument',
type: 'POST',
DataType: "html",
success: function (data) {
//I get the file content here
}
});
}
Controller:
public void saveDocument() {
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=SailBig.jpg");
Response.TransmitFile(Server.MapPath("~/MyPDFs/Pdf1.pdf"));
Response.End();
}
解决方案
I think you cannot download a file in a browser async, just redirect the user to the action and the browser will open a save dialog window. In asp.net mvc you could have an action method to download a file resulting in a FileResult
with the File
method of the base controller.
public ActionResult SaveDocument()
{
string filePath = Server.MapPath("~/MyPDFs/Pdf1.pdf");
string contentType = "application/pdf";
//Parameters to file are
//1. The File Path on the File Server
//2. The content type MIME type
//3. The parameter for the file save by the browser
return File(filePath, contentType, "Report.pdf");
}
这篇关于如何显示打开/保存对话框ASP净MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文