7
votes

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)
        )
4
I asked them this also, and they refered me to documentation which unfortunately does not have this explained.MiBu
Same here, it got me stuck for 3 days. wondering maybe you can update with the answer?reptildarat
Have you found the solution to this yet?Rosdi Kasim
Telerik's documentation is while(true) { awful }Felipe Oriani
Sorry, I don't even work for the same company anymore. I can tell you that I had more success when using their stand alone client to build their reports. I think I got that to work, but was still very problematic.Precious Roy

4 Answers

0
votes

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

0
votes

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.

0
votes

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 :)

0
votes

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.