This is a migrated thread and some comments may be shown as answers.

Getting a simple report parameter to work (ASP.NET MVC)

2 Answers 177 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 21 Dec 2017, 11:22 PM

I am having a problem getting a report parameter to work in an MVC application.  The goal is to have the report results filtered by student number.  I have the parameter and filter configured in the report designer.  I can apply the student number to the report when running the report in the designer so this problem is isolated to the MVC application specifically.  Here is some of the key code that (I think) should be sufficient to understand what I am trying to do:

Inside HomeController:

  public ActionResult StudentReport()
        {
           var uriReportSource = new UriReportSource();
            uriReportSource.Uri = "Report1.trdp";
            uriReportSource.Parameters.Add(new Parameter("StudentNumber", "120432"));
            return View();
        }

 

Inside StudentReport.cshtml:

<body>
    @(Html.TelerikReporting().ReportViewer()
        .Id("reportViewer1")      
        .ServiceUrl(Url.Content("~/api/reports"))
        .ReportSource(new UriReportSource() { Uri = "Report1.trdp" })
        .ViewMode(ViewMode.Interactive)
        .ScaleMode(ScaleMode.Specific)
        .Scale(1.0)
        .PersistSession(false)
        .PrintMode(PrintMode.AutoSelect)
        .EnableAccessibility(false)
    )

</body>

 

The error I am getting is: An error has occurred while processing Report 'Report1': Cannot perform '=' operation on System.Double and System.String.

2 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 22 Dec 2017, 05:55 PM

Is the problem related to the fact that I have already defined the parameter in the report designer and then I am using the "add new parameter feature" in the code?

uriReportSource.Parameters.Add(new Parameter("StudentNumber", "120432"));

I've attached a couple of screenshots from the report designer.  I'm wondering if the parameter and filter need to be set in code rather than in the designer.  

0
Ivan Hristov
Telerik team
answered on 28 Dec 2017, 08:23 AM
Hi Aaron,

The error seems to notify that the types of the parameter and the actual data are mismatching - the data is integer, but the parameter type is defined as string. The parameter type needs to be changed to int or the CInt() built-in conversion function should be used to convert the string to integer.

Also the parameters shouldn't be set this way in the controller, because they won't be taken into account. The parameters are set to the ReportSource and the ReportSource should be attached to the viewer. The easiest way to set the parameter is directly into the .cshtml page, as shown below:
@{
    UriReportSource rs = new UriReportSource() { Uri = "Dashboard.trdp" };
    rs.Parameters.Add("ReportYear", 2002);
 
@(Html.TelerikReporting().ReportViewer()
                .Id("reportViewer1")
                .ServiceUrl(Url.Content("~/api/reports/"))
                .ReportSource(rs)
                .ViewMode(ViewMode.Interactive)
                .ScaleMode(ScaleMode.Specific)
                .Scale(1.0)
                .PersistSession(false)
                .PrintMode(PrintMode.AutoSelect)
                .Deferred()
)
}

Check this article for another approach to set up a report source with parameters: ReportSource Model Binding.

Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Ivan Hristov
Telerik team
Share this question
or