简体   繁体   English

为什么我的“保存/打开”对话框没有弹出?

[英]Why is my save/open dialog not popping up?

I have an MVC action method which makes an ajax call to export data to excel, but the open/save dialog is not coming up. 我有一个MVC操作方法,该方法进行ajax调用以将数据导出到excel,但是打开/保存对话框没有出现。 Here is the javascript code: 这是JavaScript代码:

exportExcel = function(el, e, oSettings) {
        Json = self.searchCriteria;
    $.post(url, Json, function(data) {
    }, 'json');
};

Here is the Action Method: 这是操作方法:

public ActionResult ExportToExcel(JsonDictionary args)
    {
        var data= GetData();

        using (var package = new ExcelPackage())
        {
            string filename = "Data + ".xlsx";
            //Create the worksheet
            ExcelWorksheet ws = package.Workbook.Worksheets.Add("Data");

            //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
            ws.Cells["A1"].LoadFromCollection(data, true);

            var stream = new MemoryStream();

            package.SaveAs(stream);

            const string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            stream.Position = 0;
            return File(stream, contentType, filename);
        }
    }

The problem is that you can't download files via an ajax call. 问题是您无法通过ajax调用下载文件。 If you look at this : 如果你看这个:

http://filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/ http://filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/

this will allow an ajax file download using a dynamic iFrame. 这将允许使用动态iFrame下载ajax文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM