Hello everyone, Welcome to this
new video on rendering an RDLC report in an ASP.NET Core
application. An RDLC report is an XML based file that contains
the report layout parameters and other report related
information. RDLC reports are designed to pass data reports
from applications. We need to set four items to render an RDLC
report in the ASP.NET Report Viewer. The Reporting Service: This
service is used to interact with server side report processing.
The Processing Mode: This option specifies whether to process the
report in local or remote mode. The reports will be processed as
RDL if the processing mode is set to remote and RDLC if it is
set to local. The Report Path: This option is used to set the
path of the report that we are going to render in the ASP.NET
Report Viewer. The Data Sources: These are used to assign the
required data to the report. First I'll create a new ASP.NET
Core web application. I open Visual Studio 2022 and click
Create a New Project. I might choose ASP.NET Core Web
Application (Model-View- Controller) and then I click
Next. I change the project name and click Next. For this demo, I
set the target framework as .NET 6.0. The Bold Reports ASP.NET
Core Report Viewer works in ASP.NET Core 2, ASP.NET Core 3, and ASP.NET Core 5.0 versions. I
click Create. The new ASP.NET Core Web application will be
created. Next let me install the necessary NuGet packages in the
application. In the Solution Explorer tab, I right click the
project and choose Manage NuGet Packages. In the Browse tab, I search for
the BoldReports.AspNet. Core package and install it in
the Core application. In the same way I install the
BoldReports.Net.Core. I'll explain the purpose of each
package. The BoldReports. AspNet.Core package creates
a client side reporting control using Tag helpers. The BoldReports.Net.Core
package creates a Web API service to process the reports.
The dependent packages will be installed automatically on
installing the BoldReports.Net. Core package. Next, I need
to reference the scripts and CSS to render the Report Viewer
control. In this video I am using CDN links to reference
scripts and the stylesheet. You can also use local scripts and
themes. I have included an FAQ link for
them in the description for this video. I open the _Layout.cshtml
page in the View/Shared folder. I copy the necessary
scripts from the documentation and add them in the head tag.
This documentation link is also available in the description for
this video. Next I configure the script manager. I copy this code and replace the
code in the tag. The bold- script-manager in the body
element places the Report Viewer control initialization script in
the web page. In order to initialize the scripts properly,
the script manager should be included at the end of the body
element. Next, I open the ViewImports.cshtml file from
the Views folder, and initialize the Report Viewer
component with tag helper support. The next step is to
initialize the Report Viewer. For that I open the Index.cshtml
file from the home folder. Then I remove the
existing code and add this code. The id attribute specifies the
unique name for the Report Viewer component for this demo. I assign the value viewer to the
id attribute. Next, I create a folder named Resources in the
wwwroot folder of my application. This is where we
will keep the RDLC reports for this video. I'm going to add the
product-list.rdlc file to the Resources folder. You will find
the product-list.rdlc file link in the video description. Next, I create a class file
named ProductList.cs in the application root folder. I copy
the code from the documentation and paste it inside the
ProductList class. Next, we need to configure the Web API. The
ASP.NET Core Report Viewer requires a Web API service to
process the RDL, RDLC and SSRS report files. I create a new controller file
and name it ReportViewerController.cs
inside the controller folder. In the controller file I add the
necessary using statement. In the root attribute I add the
action placeholder and I remove the API controller attribute.
Then I inherit IReportController. I copy the necessary variables
and methods from the documentation and paste them
inside the ReportViewerController class. In
the OnInitReportOptions method, first I set the value for
processing mode to Local. Next I need to load the report as a
stream. To do that I create a variable named basePath and
assign the folder path value that has the report. Then I combine the base path
with the report path sent from Index.cshtml. Next I create
an instance for the FileStream and assign the file path to it.
I create the memory stream and copy the file stream value to it.
Then I assign the report stream value to the reportoption.
ReportModel.Stream variable. I add the data value collection
to the data source value. Here Name is case sensitive and it
should be the same as the data source name in the report
definition. The Value accepts I List, dataset and data table
inputs. Next I register the license token to remove the
license validation message. In this demo, I am going to use the
online license token. License tokens can be generated
in the Subscription section of the Bold Reports Accounts page.
I open the Program.cs file and enter the code snippet to
register the license token. I have provided the link to a
video on registering a license using online license tokens and
offline license keys. In this videos description, lets move on
to showing the product-list. rdlc with the Report Viewer. I open the Index.cshtml page
and first set the report-service- URL. This URL specifies the
service URL in which the report Viewer service is hosted. Then I
set the value for report-path and view-report-click. Then I
copy the onViewReportClick method from the documentation, and added in the Index.cshtml.
I saved the file and now everything is ready to render
the RDLC report from the ASP.NET Core application. I build and
run the application. You can see the report is loaded in the
browser. You can also bind the data source in the razor page. In
the ReportViewercontraroller .cs file, I remove the reportOption.
ReportModel.Datasources. Add() line, and save the file. Then
I open the HomeController.cs file. I create an object for the
ReportDataSource class. I assign the datasource name as the value
of the reportDataSource.Name and the value that needs to be
rendered is assigned to reportDataSource.Value. Then I assign the reportDataSource
object to the Viewbag. datasourceS. I save the file
in the Index.cshtml file. I add the Data Sources value in
the bold-report-viewer tag. I save the file. I build and run
the application. You can see the report is loaded in the browser. In this video we saw how to
create an ASP.NET Core application, how to reference
the required scripts to render an RDLC report and how to
declare the variables to bind the data source from the Web API
controller and with Razor views to render the report. I have
provided A documentation link in the description below for the
steps that we followed in this video. I have also provided a link to
our article on enabling image rendering with the report viewer
on Linux and other non Windows platforms for your reference. If
you found this video useful, don't forget to click the like
button and subscribe to our channel to watch more videos
like this. Thanks for watching.