I've recently began updating one of our projects from Reporting Q1 2013 (7.2.14.127) to Q2 2014 (8.1.14.618), but have ran into the problem of trying to pass a model to an objectdatasource. Previously, I used 8 Easy Steps to display the ReportViewer using .aspx and would use an InstanceReportSource to render the report:
aspx View
Report class:
With the new version of Telerik Reporting, InstanceReportSource is obsolete when using the new razor syntax to generate the report so we
have to use UriReportSource or TypeReportSource.
I've tried to use a custom report resolver (example at bottom of OP (Missing Report Name), and was able to pass data in using InstanceReportSource, but I wasn't able to attach any report parameters since the Model is being populated inside of the resolver (which I'd prefer not to do) and the report is created in the resolver and not actually using any parameters from the view.
.cshtml view
Report Resolver
Has anyone found a way to pass the Model directly into the report, (var report = new Report1(Model) ); or a solution that would work equally well?
aspx View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<
MyProject.Models.MyModel
>" %>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var instanceReportSource = new InstanceReportSource();
Report report = new Report1(Model);
instanceReportSource.ReportDocument = report;
ReportViewer1.ReportSource = instanceReportSource;
ReportViewer1.ViewMode = ViewMode.Interactive;
}
Report class:
using MyProject.Models;
namespace Admissions.Reports
{
using Telerik.Reporting;
public partial class Report1 : Report
{
public Report1()
{
InitializeComponent();
}
public Report1(MyModel model) : this()
{
DataSource = model;
}
}
}
With the new version of Telerik Reporting, InstanceReportSource is obsolete when using the new razor syntax to generate the report so we
have to use UriReportSource or TypeReportSource.
I've tried to use a custom report resolver (example at bottom of OP (Missing Report Name), and was able to pass data in using InstanceReportSource, but I wasn't able to attach any report parameters since the Model is being populated inside of the resolver (which I'd prefer not to do) and the report is created in the resolver and not actually using any parameters from the view.
.cshtml view
@{
var uriRS = new UriReportSource() { Uri = "1"};
}
@(
Html.TelerikReporting().ReportViewer().Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/Content/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(uriRS)
.ViewMode(ViewModes.INTERACTIVE)
.ScaleMode(ScaleModes.SPECIFIC)
.Scale(1.0)
.PersistSession(false)
)
Report Resolver
namespace Admissions.Controllers
{
public class ReportsController : ReportsControllerBase
{
protected override ICache CreateCache()
{
return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
}
protected override IReportResolver CreateReportResolver()
{
return new CustomReportResolver();
}
}
public class CustomReportResolver : IReportResolver
{
public ReportSource Resolve(string reportId)
{
var report = new Report();
report = new Report1(new DashboardViewModel { TotalRolesCount = "Hello Report World" });
var irs = new InstanceReportSource { ReportDocument = report };
return irs;
}
}
}
Has anyone found a way to pass the Model directly into the report, (var report = new Report1(Model) ); or a solution that would work equally well?