【问题标题】:Why is my save/open dialog not popping up?为什么我的保存/打开对话框没有弹出?
【发布时间】:2013-06-11 13:08:07
【问题描述】:

我有一个 MVC 操作方法,它调用 ajax 将数据导出到 excel,但是打开/保存对话框没有出现。这是javascript代码:

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

这里是动作方法:

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);
        }
    }

【问题讨论】:

    标签: c# jquery .net-3.5 epplus


    【解决方案1】:

    问题是您无法通过 ajax 调用下载文件。如果你看这个:

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

    这将允许使用动态 iFrame 下载 ajax 文件。

    【讨论】:

      猜你喜欢
      • 2021-10-17
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      相关资源
      最近更新 更多