• How to Create Visual Studio Report (rdlc) in ASP.NET MVC 4?

    by  • October 5, 2015 • Microsoft .NET Framework, Microsoft ASP.NET MVC, Microsoft SQL Server • 0 Comments


    In this article I will explains how to use Microsoft Report(rdlc) in ASP.NET MVC 4. Most of the developers use Microsoft Report (rdlc) for generating report in ASP.NET MVC 4 application. Below i am explaining how to use Microsoft Report (rdlc) in ASP.NET MVC 4.


    • .NET framework 4.0 to 4.5
    • Entity Framework
    • SQL Server 2008 to 2014
    • Visual Studio 2008 to 2015

    Follow the below steps and generate report:

    1) Add a database

    Go to Object Explorer > Right Click on Database > New Database > Enter Database name > Add.

    1.1 Create table and insert data to show in report

    Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name.

    2) Create Project

    Go to File > New Project > Select C# > Web> Asp.Net MVC and then give the name of project.

    2.1) Add entity data model

    Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.

    A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next > Choose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.

    3) Controller.cs

    Add this code in controller class to use and dispose any database.

    Use Microsoft.ReportViewer.WebForm library to get report resources.

    Dispose Method used for dispose database.

    4) View.cshtml

    5) Add report (.rdlc)

    Right Click on report folder > Add > New item > Select Report under Reporting > Enter report file name > Add.

    Here we also have to add DataSource for our report.

    Under report data Click on New > Dataset > New > Choose Data Connection > Next > Select Table > Finish.

    6) Add Action in Controller

    6.1 GetReport Method

    We can say this is a main method to generate report. This method call GetReportPath() and GetEmployeeList() Method and at the end it calls GetReportFile() and generated report as a return type.

    6.2) GetReportPath Method:

    This method finds existence report in project folder and returns report path.

    6.3) GetEmployeeList Method:

    This method is used to get all employees records from database and it returns employees as list to shown in report.

    6.4) GetReportFile Method:

    This method set the device information and converts data into file and return pdf file.

    Best WordPress Themes and Plugins with Great Team and Support!

    Avatar of Abdul Rehman


    Abdul Rehman writes on .NET technologies at GetCodeSnippet.com. GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.


    Leave a Reply