Els*_*mer 11 reportviewer webforms reporting-services asp.net-mvc-4
我正在研究一个需要使用ReportViewer从SSRS呈现远程报告的MVC4应用程序.在这个论坛的帮助下,我设法让页面在MVC下呈现,但回调不起作用(加载初始页面).导出报告工作正常(并提供所有页面).当我检查页面时,我注意到更改页面后出现以下错误:
未捕获的Sys.WebForms.PageRequestManagerParserErrorException:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息.
我发现这篇关于组合MVC和Web窗体的文章,但由于没有更多的主布局页面,它看起来已经过时了.这与如何在asp.net mvc 3 razor视图中使用reportviewer控件有关但不重复?因为那篇文章仅适用于本地报道.我已经尝试将AsyncRendering更改为true和false.如果为true,则根本不加载.任何建议将不胜感激.
最后,由于不可接受的安全风险,我最终不得不放弃原来的答案和回调标准.在我的例子中,我编写了控制器代码,将报表呈现为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;
}
Run Code Online (Sandbox Code Playgroud)