asp.net-mvc-4 - 如何在 MVC4 中呈现远程 ReportViewer aspx 页面?

标签 asp.net-mvc-4 reporting-services webforms reportviewer

我正在开发一个 MVC4 应用程序,该应用程序需要使用 ReportViewer 从 SSRS 呈现远程报告。在这个论坛的帮助下,我成功地让页面在 MVC 下呈现,但回调不起作用(加载初始页面)。导出报告工作正常(并提供所有页面)。当我检查页面时,我注意到更改页面后出现以下错误:

Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

我找到了this article结合 MVC 和 Web 表单,但它似乎已经过时了,因为没有更多的主布局页面。这与 How can I use a reportviewer control in an asp.net mvc 3 razor view? 相关但不重复。因为该文章仅适用于本地报道。我尝试将 AsyncRendering 更改为 true 和 false。当 true 时,它​​根本不加载。任何建议将不胜感激。

更新:AsyncRendering 行为 appears to have changed以前版本的 Visual Studio 之间。

最佳答案

最后,由于 Not Acceptable 安全风险,我最终不得不放弃原来的答案和回调标准。就我而言,我编写了 Controller 代码,将报告以 HTML 形式呈现为字节数组,然后从那里呈现为 FileContentResult,MVC 足够友好地将其呈现为静态 HTML 页面。导出为 PDF、Excel 或任何其他选项最终将通过将渲染参数从 HTML4.0 更改为任何合适的(PDF、XLS)和 MIME 类型,以类似的方法实现。此方法适用于 SQL Server 2008R2 及更高版本。我还没有在以前版本的 SQL Server 上尝试过。

[OutputCache(Duration = 120, VaryByParam = "id")]
public ActionResult ExportHTML(int id)
{
    // we need to add code to check the user's access to the preliminary report.
    // Also need to consolidate code between ExportHTML and ExportPDF.
    var userid = <userid>;
    var password = <password>;
    var domain = <domain>;
    IReportServerCredentials irsc = new myApp.Models.CustomReportCredentials(userid,
        password, domain);
    var parametersCollection = new List<ReportParameter>();
    parametersCollection.Add(new ReportParameter("Snapshot", id.ToString(), false));
    ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
    rv.ProcessingMode = ProcessingMode.Remote;
    rv.ServerReport.ReportServerCredentials = irsc;
    rv.ServerReport.ReportPath = <reportpath>;
    rv.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer");
    rv.ServerReport.SetParameters(parametersCollection);

    rv.ServerReport.Refresh();
    byte[] streamBytes = null;
    string mimeType = "";
    string encoding = "";
    string filenameExtension = "";
    string[] streamids = null;
    Warning[] warnings = null;

    streamBytes = rv.ServerReport.Render("HTML4.0", null, out mimeType, out encoding,
                                         out filenameExtension, out stream ids,
                                         out warnings);
    var HTMLReport = File(streamBytes, "text/html");
    return HTMLReport;
}

关于asp.net-mvc-4 - 如何在 MVC4 中呈现远程 ReportViewer aspx 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15422124/

相关文章:

c# - 更改消息默认 @Html.ValidationMessageFor mvc 4

asp.net-mvc-4 - aspnet_regiis.exe -ir 不适用于 Windows 8

reporting-services - 根据任一值或无过滤数据集

powershell - 使用 Powershell 批量更改 SSRS 数据源

c# - ASP NET session 使用 .ToString() 抛出错误

c# - Web API 服务部署在 IIS 服务器上后未运行

c# - @Html.DropDownListFor 基本用法

reporting-services - SSRS 图表中 Y 轴的指定或默认最大值

c# - 在我的 .aspx 页面上循环遍历 SQL Server 结果

c# - 在循环中对方法的多个异步方法调用