通过ViewBag在一个视图中显示多个报告
本文关键字:视图 显示 报告 一个 ViewBag 通过 | 更新日期: 2023-09-27 18:00:16
我想在一个视图中显示很多报告,但在每个div中只有一个显示。我有以下控制器代码:
ReportViewer rptViewer1 = new ReportViewer();
rptViewer1.ProcessingMode = ProcessingMode.Remote;
rptViewer1.SizeToReportContent = true;
rptViewer1.ZoomMode = ZoomMode.FullPage;
rptViewer1.AsyncRendering = true;
rptViewer1.ServerReport.ReportServerUrl = new Uri("MyServerAddress");
rptViewer1.ServerReport.ReportPath = "MyPath";
rptViewer1.ServerReport.ReportServerCredentials = new ReportViewerCredentials("MyCredentials");
ViewBag.ReportViewer1 = rptViewer1;
ReportViewer rptViewer = new ReportViewer();
rptViewer.ProcessingMode = ProcessingMode.Remote;
rptViewer.SizeToReportContent = true;
rptViewer.ZoomMode = ZoomMode.FullPage;
rptViewer.AsyncRendering = true;
rptViewer.ServerReport.ReportServerUrl = new Uri("MyServerAddress2");
rptViewer.ServerReport.ReportPath = "MyPath2";
rptViewer.ServerReport.ReportServerCredentials = new ReportViewerCredentials("MyCredentials");
ViewBag.ReportViewer = rptViewer;
return View();
和视图代码:
<div class="col-md-4">
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { frameborder = "0", width = "500", height = "500", style = "overflow:hidden;", scrolling = "no" })
</div>
<div class="col-md-4">
@Html.ReportViewer(ViewBag.ReportViewer1 as Microsoft.Reporting.WebForms.ReportViewer, new { frameborder = "0", width = "500", height = "500", style = "overflow:hidden;", scrolling = "no" })
</div>
<div class="col-md-4">
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { frameborder = "0", width = "500", height = "500", style = "overflow:hidden;", scrolling = "no" })
</div>
当我运行页面时,我有
3相同的
一行中的报告。我不知道问题出在哪里,也不知道为什么我不能显示2个唯一的报告。我看不出它在哪里崩溃,因为它编译起来没有问题。报告的2个地址是有效的,我每次都可以显示其中一个。
哪里会有问题?
它显示相同的报告,因为当DOM完全加载时,它只得到最后一个报告查看器,考虑到我的一个代码中也有相同的问题,然后我尝试如下,请看它可能会对您有所帮助。
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
@Html.Partial("DisplayClassesListFilter", null, new ViewDataDictionary { { "GridId", "classList1" }, { "GridParentDivId", "divClassList1" } })
</div>
<div class="col-md-12 classlist1 m-bottom25">
@Html.Partial("_ClassListWithoutPaging", null, new ViewDataDictionary { { "DisplayClasses", true }, { "Controller", "DisplayClasses" }, { "Action", "GetAllClassWithoutPaging" }, { "SearchFunctionName", "BuildSearchCriteriaDisplayClasses1" }, { "GridId", "classList1" }, { "GridParentDivId", "divClassList1" } })
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
@Html.Partial("DisplayClassesListFilter", null, new ViewDataDictionary { { "GridId", "classList2" }, { "GridParentDivId", "divClassList2" } })
</div>
<div class="col-md-12 classlist2 m-bottom25">
@Html.Partial("_ClassListWithoutPaging", null, new ViewDataDictionary { { "DisplayClasses", true }, { "Controller", "DisplayClasses" }, { "Action", "GetAllClassWithoutPaging" }, { "SearchFunctionName", "BuildSearchCriteriaDisplayClasses2" }, { "GridId", "classList2" }, { "GridParentDivId", "divClassList2" } })
</div>
</div>
</div>