Dear Telerik,
we are trying to use a report file Item.trdx with ObjectDataSource in .NET MVC but the view can not render my report.
1) In ReportDesigner
I created a file Item.trdx, then tried to link to a fake sqlDataSource to test in preview mode all good.
2) ObjectDataSource: I have below classes in Model (I may build these classes into class library .dll later if required)
public class
ItemLocationModel
{
public string ITEM_NO { get; set; }
public string PREV_LOC { get; set;}
}
public class ItemLocation
{
[DataObjectMethod(DataObjectMethodType.Select)]
public static IList<ItemLocationModel> GetItemLocation(string item_no)
{
List<ItemLocationModel> l =new List<ItemLocationModel>();
//fill up data here based on item_no....
return l;
}
}
3) In Controller: I am trying to use Resolver
class
CustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
{
public Telerik.Reporting.ReportSource Resolve(string item_no)
{
Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = ItemLocation.GetItemLocation(item_no);
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
report.DataSource = objectDataSource;
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
return reportSource;
}
public class ReportsController : Telerik.Reporting.Services.WebApi.ReportsControllerBase
{
protected override Telerik.Reporting.Services.Engine.IReportResolver CreateReportResolver()
{
return new CustomReportResolver();
}
protected override Telerik.Reporting.Cache.Interfaces.ICache CreateCache()
{
return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
}
}
4) In CSHTML: i am populating the ReportViewer
<div id="reportViewer1" class="k-widget">
loading...
</div>
<script type="text/javascript">
$("#reportViewer1")
.telerik_ReportViewer({
serviceUrl: "/api/reports/",
templateUrl: '/ReportViewer/templates/telerikReportViewerTemplate-9.0.15.324.html',
reportSource: {
report: 1
}
});
</script>
5) RESULT:
I debugged the Resolve() function and it clearly got data correctly, but it does not show my my report, it totally empty without any error even the template was loaded. My questions are:
- How to load data returned back from an InstantDataSource in CSHTML file?
- How to bind my returned data with a report file .trdx?
Thanks so much in advanced.
Quang