Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am returning the ReportViewer object from MVC Controller to aspx view.

Controller:
C#
[HttpPost]
        public ActionResult PortedDataReport(PortedDataReport portedDataReport)
        {
            ReportViewer mainReportViewer = new ReportViewer();
            mainReportViewer.ServerReport.ReportServerUrl =
                    new Uri("http://ServerName:8080/ReportServer");
            mainReportViewer.ServerReport.ReportPath = "/SSRS_Reports/PortingStatusReportFinal";
              
            mainReportViewer.ProcessingMode = ProcessingMode.Remote;
            //mainReportViewer.ShowParameterPrompts = false;
            mainReportViewer.ShowRefreshButton = false;
            mainReportViewer.ShowWaitControlCancelLink = false;
            mainReportViewer.ShowBackButton = false;
            mainReportViewer.ShowCredentialPrompts = false;
            
            var parametersCollection = new List<ReportParameter>();
            parametersCollection.Add(new ReportParameter("FilePortingId",portedDataReport.FileId.ToString(),false));
            parametersCollection.Add(new ReportParameter("PortedDateFrom", portedDataReport.PortedDataFrom.ToString(), false));
            parametersCollection.Add(new ReportParameter("ClientId", portedDataReport.ClintId.ToString(), false));
            parametersCollection.Add(new ReportParameter("PortedDateTo", portedDataReport.PortedDataTo.ToString(), false));
           
            mainReportViewer.ServerReport.SetParameters(parametersCollection);
            mainReportViewer.ServerReport.Refresh();
            
            portedDataReport.ReportViewer = mainReportViewer;
            return View(portedDataReport);
        }


ASPX View:

C#
<% if (Model !=null) {
              if(Model.ReportViewer != null)
              {
                  ReportViewer1.Visible = true;
                  ReportViewer1 = Model.ReportViewer;
                  ReportViewer1.Width = Unit.Pixel(1286);
                  ReportViewer1.Height = Unit.Pixel(402);
                  ReportViewer1.ServerReport.Refresh();
              //ReportViewer1.Visible = true;
              //ReportViewer1.ServerReport.ReportPath = Model.ReportViewer.ServerReport.ReportPath;
              //ReportViewer1.ServerReport.ReportServerUrl = Model.ReportViewer.ServerReport.ReportServerUrl;
              //ReportViewer1.ProcessingMode = Model.ReportViewer.ProcessingMode;


          }%>

       <% }
          else
          {
              ReportViewer1.Visible = false;
          }
          %>



But, When i run the report i am getting the following error.This is working fine when i directly bind the ReportServer URL and Path directly to the Reportviewer in aspx.

Error:

SQL
The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.
The request failed with HTTP status 404: Not Found.



Please suggest me if there is any better returning report from MVC Controller to aspx View.


Thanks,
Prasad.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900