Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi there,

I have an asp .net mvc application that I would like to embed report viewer in.

I have an action in my index.cshtml as follows:
@Html.ActionLink("Report", "Report", new { id = item.CUST_NO })


This page goes to the report method in the projectcontroller class:
C#
public void Report(string id)
      {
          SSRSReportPage a = new SSRSReportPage();
          a.btnGetReport_Click_Click(new object(), new EventArgs());
      }


This then goes to the button click event in my ReportPage.cs:
C#
public void btnGetReport_Click_Click(object sender, EventArgs e)
      {

           deceasedc = new FNB_DeceasedClientsController();

          ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;

              ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://fit-rbgvdi/Reportserver");

              ReportViewer1.ServerReport.ReportPath = "/COB/COB";

          //Pass Parametrs's value here.
          ReportParameter[] reportParameterCollection = new ReportParameter[1];       //Array size describes the number of paramaters.
          reportParameterCollection[0] = new ReportParameter();
          reportParameterCollection[0].Name = "cust_no";                                 //Give Your Parameter Name
          reportParameterCollection[0].Values.Add(rvalue);
          ReportViewer1.ServerReport.SetParameters(reportParameterCollection);
          ReportViewer1.ServerReport.Refresh();

          }


I keep getting an error on
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;


System.NullReferenceException; Object reference not set to an instance of an object.

Any ideas?

What I have tried:

I have tried entering a report viewer package and an object as above.
Posted
Updated 2-Dec-16 5:02am

1 solution

You're getting that exception because ReportViewer1 has not been set to an instance of the ReportViewer class.

To find out why, you'll need to debug your code.

NB: Rather than trying to create and invoke a WebForms page, you might want to look at using a proper MVC report viewer library - for example:
 
Share this answer
 

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