Server-side controls are not supported by default in the MVC view, so in order to be able to load reports through the Report Viewer control, you need to add embedded pages in the MVC view.
At first find a solution on StackOverflow, see here. However, one of the biggest drawbacks of this solution is that page navigation is not supported, that is, only the first page of the report is displayed.
Because, the original author also said, the MVC page does not support the navigation control post back, it will not work properly.
See the comments that some people say that IFRAME can solve the problem of multi-page report, and then tried to finally succeed.
1. Create a new WebForm1.aspx in the project and modify the Global.asax.cs to make the ASPX page accessible directly.
Routes. Ignoreroute ("Webforms/{weform}");
2. Add an IFRAME definition to the attempt page that needs to load the report, and add a reference to the WebForm1.aspx.
<iframe id= "IFR" src= ". /webforms/webform1.aspx "width=" 900px "height=" 700px "frameborder=0></iframe>
Add the Report Viewer control to the 3.webform1.aspx and reference the design's reports.
<form id= "Form1" runat= "Server" > <asp:scriptmanager id= "ScriptManager1" runat= "Server" ></asp: scriptmanager> <asp:updatepanel id= "UID" runat= "Server" > <ContentTemplate> <rsweb:reportvie Wer id= "ReportViewer1" runat= "Server" asyncrendering= "false" height= "800px" width= "900px" showfindcontrols= " False " showbackbutton=" false "pagecountmode=" Actual "></rsweb:ReportViewer> </ContentTemplate>
</asp:UpdatePanel></form>
4. In the Page_Load method of the background code, add the data source.
ReportViewer1.LocalReport.ReportPath = Server.MapPath ("~/REPORTS/REPORT1.RDLC"); ReportDataSource ReportDataSource = new ReportDataSource ("DataSet1", Yourdatasource); REPORTVIEWER1.LOCALREPORT.DATASOURCES.ADD (ReportDataSource); ReportViewer1.LocalReport.Refresh ();
5. Now the report can be displayed, but in order for the report to receive the parameters of the page, you need to add a bit of code. In the Refresh method of the View page, specify a different URL address for the IFRAME, depending on the filter criteria.
function Reloaddata () { var fil = filterfield.value; var urlstr = Ifr.location.href + '? filter= ' + fil; Ifr.window.location.href=urlstr; }
6. In the background code of WebForm1.aspx, get the URL parameter.
String filter= request.querystring["Filter"];
7. Apply the parameters to the data query so that you can update the report's display data through a page query.
Using an IFRAME to load an RDLC report under Razor view