Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Net Mvc:如何通过Ajax调用加载RDLC报告_C#_Jquery_Ajax_Asp.net Mvc_Rdlc - Fatal编程技术网

C# Net Mvc:如何通过Ajax调用加载RDLC报告

C# Net Mvc:如何通过Ajax调用加载RDLC报告,c#,jquery,ajax,asp.net-mvc,rdlc,C#,Jquery,Ajax,Asp.net Mvc,Rdlc,我有一个控制器操作,它通过return File()函数返回RDLC报告。通过浏览器地址栏调用此操作时,输出正常。同样,当通过ajaxget方法调用此操作时,成功数据将以字符串形式显示。我只想在新窗口中以PDF文件的形式显示ajax调用的输出。有办法吗?我不想将参数作为window.open()函数的查询字符串发送,该函数用于从浏览器地址栏调用操作 success: function (data) { var w = window.open(); $(w.document.

我有一个控制器操作,它通过return File()函数返回RDLC报告。通过浏览器地址栏调用此操作时,输出正常。同样,当通过ajaxget方法调用此操作时,成功数据将以字符串形式显示。我只想在新窗口中以PDF文件的形式显示ajax调用的输出。有办法吗?我不想将参数作为window.open()函数的查询字符串发送,该函数用于从浏览器地址栏调用操作

success: function (data) { 
     var w = window.open();
     $(w.document.body).html(data);
     }
%PDF-1.3 1 0 obj[/PDF/Text/ImageB/ImageC/ImageI]endobj 4 0 obj
>流X}N� �0���M���\�籅v�8.�� ��u> /Font
>>>>>endobj 3 0 obj
>endobj 5 0 obj
>endobj 6 0 obj
>endobj 7 0 obj
>endobj外部参照0 8 0000000000 65535 f 00000000 10 00000 n 0000000 266 00000 n
0000000 429 00000 n 00000000 65 00000 n 0000000 529 00000 n 0000000 591 00000 n 0000000 643 00000N拖车

>startxref 957%%EOF
您必须使用此选项,而不是窗口。open()使用此选项

您可以轻松地在此操作中放置代码

public ActionResult Download()

    {

        LocalReport localReport = new LocalReport();
        localReport.ReportPath = Server.MapPath("~/Reports/PatientRecipt.rdlc");
        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "DataSet1";
        //reportDataSource.Name = "PatientRecipt";
        reportDataSource.Value = applicationDbContext.TblInvoices.Select(x => x).ToList();
        localReport.DataSources.Add(reportDataSource);
        string reporttype = "PDF";
        string mimeType;
        string encoding; string[] streams;
        Warning[] warnings;
        byte[] renderedByte;
        renderedByte = localReport.Render(reporttype, "", out mimeType, out encoding, out reporttype, out streams, out warnings);

        Response.AddHeader("content-disposition", "attachment;filename = expens_report." + reporttype);

        return File(renderedByte, reporttype);

    }

不能使用ajax下载文件。请参阅使用重定向以获取返回文件的操作方法。您可以传递所有必需的参数,并在该操作方法内创建报告。@TetsuyaYamamoto我是这样做的,因为Stephen Muecke link说我想要的方法是不可能的。
public ActionResult Download()

    {

        LocalReport localReport = new LocalReport();
        localReport.ReportPath = Server.MapPath("~/Reports/PatientRecipt.rdlc");
        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "DataSet1";
        //reportDataSource.Name = "PatientRecipt";
        reportDataSource.Value = applicationDbContext.TblInvoices.Select(x => x).ToList();
        localReport.DataSources.Add(reportDataSource);
        string reporttype = "PDF";
        string mimeType;
        string encoding; string[] streams;
        Warning[] warnings;
        byte[] renderedByte;
        renderedByte = localReport.Render(reporttype, "", out mimeType, out encoding, out reporttype, out streams, out warnings);

        Response.AddHeader("content-disposition", "attachment;filename = expens_report." + reporttype);

        return File(renderedByte, reporttype);

    }