We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Implement Class Object List as Report Data source

Thread ID:

Created:

Updated:

Platform:

Replies:

146126 Jul 20,2019 07:15 PM UTC Jul 25,2019 06:47 AM UTC Report Platform 3
loading
Tags: Report Viewer
Pasang Tamang
Asked On July 20, 2019 07:15 PM UTC

Hi,
I am new to Syncfusion report and designer. I am trying to change the report framework in one of my project which is in ASP.NET Core MVC. I have a list of data that I use to get from entity framework code first. My class looks like below
public class Students{
public string Name{get;set;}
public int RollNo{get;set;}
public string ClassName{get;set;}
public List SubjectMarks{get;set;}
}
public class SubjectMarks{
public string SubjectName{get;set;}
public decimal FullMarks{get;set;}
public decimal PassMarks{get;set;}
public decimal ObtainedMarks{get;set;}
public List Activity{get;set;}
}
public class SubjectActivityMarks{
public string ActivityName{get;set;}
public decimal ObtainedMarks{get;set;}
}
So I would like to use generated object of above class combination in syncfusion report. Is it possible to use?
Also I tried to use web api data source data generated using above class object. But it throws json format required error. I manually browsed the web api path and copied the json data to validate in third party tool like jsonlint and there it shows json data is valid.
Could you please help me on both of the scenario?
Thanks
Pasang

Vinoth Srinivasan [Syncfusion]
Replied On July 22, 2019 09:48 AM UTC

Hi Pasang, 
 
Thanks for your interest in Syncfusion components. 
 
Please find the below response for your queries. 
 
Query 
Response 
I am new to Syncfusion report and designer. I am trying to change the report framework in one of my project which is in ASP.NET Core MVC. I have a list of data that I use to get from entity framework code first. My class looks like below 
Yes, we can able to pass the local object model data for datasource in our ASP.NET Core ReportViewer application. Please find the below help documentation for how to use the local object model for datasource. 
 
We have prepared a simple sample in ASP.NET Core ReportViewer for your reference and it can be downloaded from below location. 
 
So I would like to use generated object of above class combination in syncfusion report. Is it possible to use? 
Could you please provide some additional details like how you are using our reporting control, whether you are using ReportViewer with ReportServer or without ReportServer at your end. It will be helpful for us to provide the solution at the earliest. 
Also I tried to use web api data source data generated using above class object. But it throws json format required error. I manually browsed the web api path and copied the json data to validate in third party tool like jsonlint and there it shows json data is valid. 
Could you please help me on both of the scenario? 
 
We were not able to find the exact root cause for this mentioned JSON data issue. So, could you please share your code snippet how you are specifying the data in web API. It is very useful to provide the solution earlier. 
 
 
Regards, 
Vinoth S. 


Pasang Tamang
Replied On July 22, 2019 10:43 AM UTC

Hi,

Many thanks for your reply.

I am using Report Server to design report (rdl) file and goal is to use that rdl file in ASP.NET Core application. In my ASP.NET Core application I already have methods that returns data as expected in PDF form. Now I want to replace those PDF by Syncfusion ReportViewer. I have attached screenshot to have idea how my expected output is. 



Below is the API code I am using

    [Route("api/[controller]")]
    [ApiController]
    public class ExamReportController : ControllerBase
    {
[Route("GetMarksheet")]
[HttpGet]
public IActionResult GetMarksheet([FromQuery]int classId, [FromQuery]int sectionId, [FromQuery]int examId, [FromQuery]int schoolId, [FromQuery]int sessionId)
    {
var modelList = new List();
//my code to generate data and assign to modelList goes here
var finalModel = modelList.OrderBy(x => x.RollNo).ToList();
var datas = JsonConvert.SerializeObject(finalModel);
return Ok(datas);
    }
    }

Thanks

Regards,
Pasang

Vinoth Srinivasan [Syncfusion]
Replied On July 25, 2019 06:47 AM UTC

Hi Pasang, 
 
Sorry for the delay. 
 
Please find the below response for your queries. 
 
Query 
Response 
I am using Report Server to design report (rdl) file and goal is to use that rdl file in ASP.NET Core application. In my ASP.NET Core application I already have methods that returns data as expected in PDF form. Now I want to replace those PDF by Syncfusion ReportViewer. I have attached screenshot to have idea how my expected output is.  
 
Yes, we can able to pass the local object model values for RDL report when setting the processing mode as local as shown in below code example. 
 
Index.cshtml: 
@{ 
    ViewData["Title"] = "ReportViewer ASP.NET CORE Support"; 
} 
<style> 
    body, html, #reportviewer { 
        overflow: hidden !important; 
        height: 100%; 
        width: 100%; 
    } 
</style> 
<sf-report-viewer id="reportviewer1" report-service-url="../Home" processing-mode="Local" /> 
<sf-script-manager></sf-script-manager> 
 
HomeController.cs: 
  public void OnInitReportOptions(ReportViewerOptions reportOption) 
        { 
            string basePath = _hostingEnvironment.WebRootPath; 
            FileStream reportStream = new FileStream(basePath + @"\Report\Region.rdl", FileMode.Open, FileAccess.Read); 
            reportOption.ReportModel.Stream = reportStream; 
 
            reportOption.ReportModel.DataSources.Clear(); 
            reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData() }); 
        } 
 
        public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
 
        } 
    } 
 
    public class StoreSales 
    { 
        public int SalesOrderID { get; set; } 
        public double TotalDue { get; set; } 
        public int CustomerID { get; set; } 
        public string Store { get; set; } 
        public string StateProvinceCode { get; set; } 
 
        public static List<StoreSales> GetData() 
        { 
            List<StoreSales> sales = new List<StoreSales>(); 
            StoreSales strSal = null; 
            strSal = new StoreSales() 
            { 
                SalesOrderID = 43659, 
                TotalDue = 23153.2339, 
                CustomerID = 29825, 
                StateProvinceCode = "GA", 
                Store = "Better Bike Shop" 
            }; 
 
We have prepared the simple sample for your reference and it can be downloaded from below location. 
Below is the API code I am using 
 
    [Route("api/[controller]")] 
    [ApiController] 
    public class ExamReportController : ControllerBase 
    { 
                            [Route("GetMarksheet")] 
                             [HttpGet] 
                             public IActionResult GetMarksheet([FromQuery]int classId, [FromQuery]int sectionId, [FromQuery]int examId, [FromQuery]int schoolId, [FromQuery]int sessionId) 
                  { 
                                           var modelList = new List(); 
                                            
                                           //my code to generate data and assign to modelList goes here 
                                            
                                           var finalModel = modelList.OrderBy(x => x.RollNo).ToList(); 
                                           var datas = JsonConvert.SerializeObject(finalModel); 
                                           return Ok(datas); 
                  } 
    } 
 
Based on your code snippet the Json data has been returned properly. So, it possible for you to modify the above sample to reproduce the issue at our end. 
 
 
Regards, 
Vinoth S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon