2016-08-05 55 views
1

我想在一個視圖中顯示大量報告,但在每個div中只顯示一個。 我有以下的控制器代碼:ViewBag在一個視圖中顯示許多報告

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個報告地址是有效的,每次我都可以顯示其中的一個。

哪裏可以成爲問題?

回答

0

它顯示相同的報表,因爲當DOM負載完全它只能得到最後的ReportViewer考慮,我在我的代碼一個也紛紛同樣的問題,那我也試試如下,敬請期待可以幫助你。

<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> 
+0

我可以在哪裏找到您的解決方案ReportViewer? – Sowiarz

+0

在視圖代碼中,您必須根據傳遞的ViewDataDictionary在報表查看器中作出決定 –

+0

您可以向我展示如何將其固定在下面的代碼中? – Sowiarz