7

I've tried the MVC helper and the standard HTML5 viewer. I'm curious if anyone has been able to successfully load a report containing parameters using the new viewers. I cannot get any feedback from Telerik.

@{
    var report = new UriReportSource() { Uri = "TestReport.trdx" };
    report.Parameters.Add(new Telerik.Reporting.Parameter() { Name="UserId", Value=1234 });
    report.Parameters.Add(new Telerik.Reporting.Parameter() { Name = "UserName", Value = "Test User" });
}
@(Html.TelerikReporting().ReportViewer()
           .Id("reportViewer1")
           .ServiceUrl("/api/reports/")
           .TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
               .ReportSource(report)
           .ViewMode(ViewModes.INTERACTIVE)
           .ScaleMode(ScaleModes.SPECIFIC)
           .Scale(1.0)
           .PersistSession(false)
        )
Precious Roy
  • 1,086
  • 1
  • 9
  • 19

4 Answers4

0

Wondering if you already tested How To: Pass values to report parameters in Telerik Reporting documents or not.

Farhad
  • 533
  • 9
  • 21
0

You need to declare the report data source separately and then pass it for example

@{
       var dataSource = new UriReportSource() { Uri = "rptUncashedCheckLetter.trdx" };
        dataSource.Parameters.Add(new Telerik.Reporting.Parameter() { Name = "CheckNumber", Value = "2315527" });

    }

    @(Html.TelerikReporting().ReportViewer()
           .Id("reportViewer1")
           .ServiceUrl("/api/reports/")
           .TemplateUrl("/Reports/telerikReportViewerTemplate.html")
           .ReportSource(dataSource)
           .ViewMode(ViewModes.INTERACTIVE)
           .ScaleMode(ScaleModes.FIT_PAGE_WIDTH)
           .Scale(1.0)
           .PersistSession(false)
           )

There doesn't seem to be a way to do it directly when using the MVC version.

Gumbo
  • 81
  • 1
  • 2
  • can you please help me https://stackoverflow.com/questions/76953236/error-happening-telerik-reporting-html5-with-net6 – sina_Islam Aug 22 '23 at 16:25
0

In .cshtml as header you have @model yourModel

Then to create the report you have:

     UriReportSource urs = new UriReportSource (){
        Uri = "Report1.trdx" 
    };
    urs.Parameters.Add("id", Model.id.ToString());
    urs.Parameters.Add("start", Model.Start.ToString());
    urs.Parameters.Add("end", Model.Stop.ToString());

    @(Html.TelerikReporting().ReportViewer()
           .Id("reportViewer1")
           .ServiceUrl("/api/reports/")
           .TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
           .ReportSource(urs)
           .ViewMode(ViewModes.INTERACTIVE)
           .ScaleMode(ScaleModes.SPECIFIC)
           .Scale(1.0)
           .PersistSession(false))

And the Model.cs file:

 public class yourModel
{
    public Guid id{ get; set; }

    public DateTime Start { get; set; }

    public DateTime Stop { get; set; }}

This is the way i did it,hope it helps :)

Zippy
  • 1,804
  • 5
  • 27
  • 36
0

If all parameters were set, most probably the problem lies in the Newtonsoft.Json.dll. Your problematic project most probably references the GAC version of Newtonsoft. In order to fix check if Newtonsoft is still installed in the GAC and remove it if so. For a quick fix just delete the Newtonsoft reference from your project and add it using nuget.