This question is locked. New answers and comments are not allowed.
I've recently began updating one of our projects from Reporting Q1 2013 to Q2 2014, but have ran into the problem of trying to pass a Model to an objectdatasource. Previously, I used http://blogs.telerik.com/careypayette/posts/13-03-26/telerik-reporting-in-mvc-sure-it-takes-8-quick-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 (http://www.telerik.com/forums/%27bad-request%27---%27missing-report-name%27-when-using-instancereportsource-in-asp-net-mvc-report-viewer), 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.
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.
@{
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)
)
I've tried to use a custom report resolver (example at bottom of OP (http://www.telerik.com/forums/%27bad-request%27---%27missing-report-name%27-when-using-instancereportsource-in-asp-net-mvc-report-viewer), 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.
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?