加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 00:19:54 所属栏目:asp.Net 来源:网络整理
导读:我正在研究一个需要使用ReportViewer从SSRS渲染远程报告的MVC4应用程序.在这个论坛的帮助下,我设法让页面在MVC下呈现,但回调不起作用(加载初始页面).导出报告工作正常(并提供所有页面).当我检查页面时,我在更改页面后发现以下错误: Uncaught Sys.WebForms.P
我正在研究一个需要使用ReportViewer从SSRS渲染远程报告的MVC4应用程序.在这个论坛的帮助下,我设法让页面在MVC下呈现,但回调不起作用(加载初始页面).导出报告工作正常(并提供所有页面).当我检查页面时,我在更改页面后发现以下错误:

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

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

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

解决方法

最后,由于不可接受的安全风险,我最终不得不放弃原来的答案和回调标准.在我的例子中,我编写了控制器代码,将报表呈现为HTML到字节数组,然后从那里到FileContentResult,MVC非常友好地呈现为静态HTML页面.通过将Render参数从HTML4.0更改为适当的(PDF,XLS)和MIME类型,最终将以类似的方式实现导出为PDF,Excel或任何其他选项.此方法适用于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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读