2
Answers

RDLC Report Dot Net Core MVC

Piyush Mohan

Piyush Mohan

1y
1.3k
1

How to create RDLC report in asp.net core mvc 5 with Report Viewer 

Answers (2)
1
Mayooran Navamany

Mayooran Navamany

277 6.8k 178.4k 1y

Read below the Articles it's helpful for you 

01. https://www.c-sharpcorner.com/UploadFile/1e050f/create-rdlc-reports-in-Asp-Net-web-applicationwebsite/

02. https://help.boldreports.com/report-viewer-sdk/aspnet-core-reporting/report-viewer/how-to/create-rdlc-report/

03. https://www.aspsnippets.com/Articles/Implementing-RDLC-Reports-in-ASPNet-MVC.aspx

1
Rajkiran Swain

Rajkiran Swain

28 40.7k 3.4m 1y

Step 1: Install the necessary packages

  • Install the Microsoft.ReportingServices.ReportViewerControl.WebForms package from NuGet. This package provides the Report Viewer control for ASP.NET Core.

Step 2: Create a new RDLC report

  • Right-click on your project, go to Add -> New Item.
  • Select "Report" from the Visual C# Items -> Reporting category.
  • Name the report and click "Add".
  • Design your report using the RDLC designer.

Step 3: Configure Report Viewer in the View

  • In your MVC View where you want to display the report, add the following code to include the Report Viewer control:
@{
    ViewData["Title"] = "Report View";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Report View</h2>

<!-- Report Viewer control -->
<rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>

@section scripts{
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/Microsoft.Reporting.WebForms/jsreportviewer.js"></script>
}

 

Step 4: Configure the controller action to render the report

  • In your controller, add an action method to retrieve the data and render the report:
using Microsoft.Reporting.WebForms;

public class ReportController : Controller
{
    public IActionResult Index()
    {
        // Create a new LocalReport object
        LocalReport localReport = new LocalReport();

        // Specify the path to the RDLC report file
        string reportPath = Path.Combine(Server.MapPath("~/Reports"), "YourReport.rdlc");
        localReport.ReportPath = reportPath;

        // Set the data source for the report (e.g., retrieve data from a database)
        // ...

        // Set the report parameters if needed
        // ...

        // Render the report into a byte array
        byte[] reportBytes = localReport.Render("PDF");

        // Return the report as a FileResult
        return File(reportBytes, "application/pdf", "Report.pdf");
    }
}

 

Make sure to replace "YourReport.rdlc" with the actual filename of your RDLC report.

Step 5: Configure the route to the controller action

  • In your Startup.cs file, add a route to map the URL to the controller action:
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "report",
        pattern: "report",
        defaults: new { controller = "Report", action = "Index" });
});

 With these steps, you should be able to create and display an RDLC report in ASP.NET Core MVC 5 using the Report Viewer control.