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. Image for the cookie policy date
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

Add datasource into reportviewer under asp.net core 2.2 or above

Hi All:

Can I set viewdata , viewbag / model to reportviewer.datasource  in mvc core ?

Thank you

7 Replies

MS Mahendran Shanmugam Syncfusion Team December 17, 2019 01:18 PM UTC

Hi Michael, 

Yes we can able to pass the datasource from ViewBag in our ASP.NET Core Report Viewer control. Please find the below code snippet for your reference. 
Index.cshtml: 
<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" dataSources="ViewBag.dataSources" processing-mode="Local" ></bold-report-viewer> 


HomeController.cs: 
public IActionResult Index() 
        { 
            ReportDataSource reportDataSource = new ReportDataSource(); 
            reportDataSource.Name = "StoreSales"; 
            reportDataSource.Value = StoreSales.GetData(); 
            ViewBag.dataSources = new List<ReportDataSource> { reportDataSource }; 
            return View(); 
        } 

Regards, 
Mahendran S. 



MK Michael K December 18, 2019 03:36 PM UTC

Dear Mahendran:

Thansk for your help, that is what I want




SS Swetha Srikumar Syncfusion Team December 19, 2019 05:18 AM UTC

Hi Michael, 
  
Thanks for the update. 
  
Regards, 
Swetha 



MK Michael K December 20, 2019 09:20 AM UTC

Hi Mahendran:

Can I know the know the code in "/api/ReportViewer" ?

Thank you


VS Vinoth Srinivasan Syncfusion Team December 23, 2019 05:07 AM UTC

Hi Michael, 

It is our ReportServiceURL to connect the server-side controller in our client side. For your reference please find the below help documentation. 

Regards, 
Vinoth S. 



MK Michael K December 26, 2019 03:25 AM UTC

Dear Vinoth :

Thanks for your prompt, I have tried to do, but the error. 
Firstly, I try to copy the template code from your web page

Then in the viewer code : I add this

<h1>PreviewReport</h1>

<bold-report-viewer id="viewer" report-path="CurrentListv15.rdl" report-service-url="/api/ReportViewer" dataSources="ViewBag.dataSources" processing-mode="Local"></bold-report-viewer> 

For the Homecontroller, I write this
public IActionResult PreviewReport()
        {
            ReportDataSource reportDataSource = new ReportDataSource();
            reportDataSource.Name = "dtClassRecords";
            using (DBPool = new DBPool())
            {
                reportDataSource.Value = db.dsClassMate.FromSqlRaw("SELECT TOP 500 * FROM [ClassMate]").ToList();
                ViewBag.dataSources = new List<ReportDataSource> { reportDataSource };
                return View();
            }
          
        }

When I run it , the report viewer display "Unable to cast object of type 'System.Text.Json.JsonElement' to type 'System.String'."
Can you advise something ?

Thank you 

 


VS Vinoth Srinivasan Syncfusion Team December 30, 2019 06:45 AM UTC

Hi Michael, 

We have validated the mentioned issue by passing the datasource via ViewBag and it is rendering properly at our end. So, could you please share your issue reproducible application with us to validate the reported problem at our end. 

Regards, 
Vinoth S. 


Loader.
Live Chat Icon For mobile
Up arrow icon