我正在研究一个需要使用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; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。