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

我正在研究一个需要使用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;
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....