how to use objectdatasource with report file in .NET MVC

4 posts, 0 answers
  1. quang
    quang avatar
    1 posts
    Member since:
    May 2015

    Posted 19 May 2015 Link to this post

    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
            public string ITEM_NO { get; set; }
            public string PREV_LOC { get; set;}       

    public class ItemLocation
            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

    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">
        <script type="text/javascript">
                    serviceUrl: "/api/reports/",
                    templateUrl: '/ReportViewer/templates/telerikReportViewerTemplate-',
                    reportSource: {
                        report:  1


    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.


  2. Nasko
    Nasko avatar
    1087 posts

    Posted 21 May 2015 Link to this post

    Hello Quang,

    The following line from your code:
    Telerik.Reporting.Report report = new Telerik.Reporting.Report();

    creates an empty report object. This report does not contain any sections or any items. It is an empty report, which will be blank when displayed inside a report viewer.

    In order to display your report, you need to work with the Item.trdx file, deserialize it to a report object, as explained in the Serializing Report Definition in XML help article, and then modify its data source to reference the new ObjectDataSource component.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. 仁劭
    仁劭 avatar
    3 posts
    Member since:
    May 2018

    Posted 08 Jun 2018 Link to this post

    In this case If I don't want to use item.trdx 
    I want to use the ReportLibrary the report1.cs
    How can I Pass the object source from the web site 

    In the picture , I Create a class like UserInfo 

    And I create a method named GetUserInf()
    I can build and get answert by the picture but now If  passing a string It will be not work 
    can I use the reportController Passing Object to the Report1.cs ?

  4. Todor
    Todor avatar
    559 posts

    Posted 12 Jun 2018 Link to this post

    Hi 仁劭,

    You can instantiate the report in the Resolve() method of the CustomReportResolver, assign its DataSource and return it wrapped in an InstanceReportSource, i.e.

    public Telerik.Reporting.ReportSource Resolve(string reportId)
        Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
        objectDataSource.DataSource = GetUserInfo();
        Report1 report = new Report1();
        report.DataSource = objectDataSource;// you can use also GetUserInfo() directly since it is a List
        Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
        reportSource.ReportDocument = report;
        return reportSource;

    Note that the string passed to the Resolve() method (i.e. reportId in the above code snippet) is intended to be used to identify the report. If necessary other information can also be included there. Custom logic can be used to split the information carried by reportId and used to identify the report, data source, etc.

    The place where the report can be modified (i.e. the information related to the report definition can be changed) after being passed from the Html5 Report Viewer is the Resolve() method of the Report Resolver of the Telerik Reporting REST Service. The method must return a valid server side ReportSource that will be used by the Reporting Engine.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top