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

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

Thread ID:

Created:

Updated:

Platform:

Replies:

149911 Dec 13,2019 04:10 PM UTC Dec 30,2019 06:45 AM UTC ASP.NET Core 7
loading
Tags: ReportViewer
Michael K
Asked On December 13, 2019 04:10 PM UTC

Hi All:

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

Thank you

Mahendran Shanmugam [Syncfusion]
Replied On 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. 


Michael K
Replied On December 18, 2019 03:36 PM UTC

Dear Mahendran:

Thansk for your help, that is what I want



Swetha Srikumar [Syncfusion]
Replied On December 19, 2019 05:18 AM UTC

Hi Michael, 
  
Thanks for the update. 
  
Regards, 
Swetha 


Michael K
Replied On December 20, 2019 09:20 AM UTC

Hi Mahendran:

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

Thank you

Vinoth Srinivasan [Syncfusion]
Replied On 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. 


Michael K
Replied On 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 

 

Vinoth Srinivasan [Syncfusion]
Replied On 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. 


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