首页 新闻 赞助 找找看

mvc3+ajax下载rdlc报表,不能保存。

0
悬赏园豆:5 [已解决问题] 解决于 2012-09-20 08:43

用MVC3和miniui做了一个项目,其中有一块是打印报表。

用的是rdlc报表。

后台代码:

   //打印派车单
        public ActionResult PCD_Print()
        {
            string strPCDL = Request["DisID"];
            strPCDL = "123487";
            IV_Export_PCD_PrintService db = new V_Export_PCD_PrintService();
            Expression<Func<V_Export_PCD_Print, bool>> whereLambda = u => u.pcdl == strPCDL;
            IQueryable<V_Export_PCD_Print> query = db.LoadEntites(whereLambda);

            LocalReport localReport = new LocalReport();
            localReport.ReportPath = "../QSMC.EITruck.Report/Dispatch_Print.rdlc";
            ReportDataSource reportDataSource = new ReportDataSource("PCD_Print_DataSet", query.ToList<V_Export_PCD_Print>());

            localReport.DataSources.Add(reportDataSource);
            string reportType = "PDF";
            string mimeType;
            string encoding;
            string fileNameExtension;

            //The DeviceInfo settings should be changed based on the reportType
            //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
            string deviceInfo =
            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>8.3in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>1cm</MarginLeft>" +
            "  <MarginRight>1cm</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            //Render the report
            renderedBytes = localReport.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
            return File(renderedBytes, mimeType);

        }

前台代码

///打印派车单
function onClickPrint(e) {
//    if (!IfConfirm) {
//        mini.alert('请先保存派车单明细!<br>请先Confirm派车单 ');
//        return;
//    }
    var DisID = mini.get("txtDisID").getValue();
    $.ajax({
        url: WebRootPaht + "../../../Print/PCD_Print",
        type: "post",
        data: { DisID: DisID },
        success: function (text) {
           
        },
        error: function () {
            mini.alert("打印失败!");
        }
    });

运行后不能下载文档。

后来用IE9和Chrome调试,发现请求和相应结果都是正确的,

特别是在IE9下面将响应结果保存为PDF文件后是正常打开的(如下图),问题是如果将结果自动保存到本地呢?

我感觉是

  success: function (text) {
           
        },
里面少了点什么,就是如何将反馈结果保存到本地文档。这里面该如何写呢?

Gamain的主页 Gamain | 菜鸟二级 | 园豆:357
提问于:2012-09-19 16:54
< >
分享
最佳答案
0

click:

window.open(WebRootPaht + "../../../Print/PCD_Print")

<iframe style="display:none"...

iframe的.src=WebRootPaht + "../../../Print/PCD_Print"

收获园豆:5
向往-SONG | 老鸟四级 |园豆:4853 | 2012-09-19 17:00

经测试这两个都可以。但是第一个会造成浏览器拦截弹出框的问题,所以用了第二个。

非常感谢。

Gamain | 园豆:357 (菜鸟二级) | 2012-09-20 08:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册