---
title: "RDLC report in MVC application"  
description: "1). How to create a rdlc report in MVC application?  2). Generate RDLC report in asp.net MVC application?"  
author: "Anonymous User"  
published: 2018-10-29  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/23249/rdlc-report-in-mvc-application  
category: "c#"  
tags: ["c#", "asp.net mvc", "mvc", "mvc4", "mvc5"]  
reading_time: 5 minutes  

---

# RDLC report in MVC application

## RDLC Report

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/78278dc4-78b8-4bec-9d90-48495cf63c39.png)**\**

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/54135b95-03b9-40a1-b80d-ca3c87ed3325.png)**\**

Hi Friends,

Today I am going to create an MVC project with RDLC reporting service (step by step).

**1).** Create a Database in SQL server.

**2).** Create a table in that database.

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/ef194a90-48a6-4d9b-97c3-4c743824ae03.png)

**3).** Open Visual Studio an create a new project.

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/2b974e00-34b3-4939-a127-580532a97b32.jpeg)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/a1db9dde-bf32-46bc-9d91-367f4f656693.jpeg)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/c353d4cf-890a-4668-b1c4-19b4744e7d15.png)\

**4).** Add an **edmx** file in the **Model** **folder** : RightClick on the **Model folder** in Solution Explorer section and select **new item**

\

| ![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/d41f5533-cd05-432b-8d9e-a9bc0bdf2392.png)\ | ![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/e6f627fe-dbe9-43cc-87f0-c6dda47f4bea.jpeg)\ |
| --- | --- |

\

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/21e65c9c-f318-49e8-a207-3e3b1829f0aa.jpeg)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/e61c5501-4080-49a2-a723-b205785256e8.jpeg)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/cb5cf0a2-65a6-4c71-a80e-7ad5ba9630e5.jpeg)

and finally, add your **edmx file**.

**5).** Then After adding your **edmx file** then after, go to solution explorer and right click on your main project and add a new folder with the name of "**Report**".

then after creating Report folder, and again select that folder(Report) and do right-click on it and select new_item and click, then search **Reporting service**

in open wizard and select **Report** option on there.

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/6cd33893-1db3-4a19-8bbe-bcfaf2751cd9.png)\

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/b4ff17ad-f80c-43ce-b0a0-ff9bc41979b3.png)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/b1179ae1-129f-43cd-a025-6339a80678de.png)\

\

**6).** Create a table or **DataSet** on right-click.

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/a845d118-bf65-4b50-a7ac-bdc37916f22c.png)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/7a942996-77a8-4767-942f-f681e42331bd.png)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/ada4f4fb-4ea0-4d64-bea3-274b89bb1e9f.png)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/ad4468e7-2d58-40b5-9cfd-2bc583940c73.png)

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/16956ae1-a23d-4290-9194-955e499475f0.png)

**7).** Design for your display report. like Add **Header and Footer** section.

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/b191e8e3-2bba-441f-8698-7d667164588e.png)

**8).** Open Controller folder in solution explorer section and select & open "HomeController.cs"

and add the code for their actions.

```
using Microsoft.Reporting.WebForms;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.Mvc;
namespace MvcApplication15.Controllers{    public class HomeController : Controller    {        public ActionResult Index()        {            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";            return View();        }        public ActionResult About()        {            ViewBag.Message = "Your app description page.";            return View();        }        public ActionResult Contact()        {            ViewBag.Message = "Your contact page.";            return View();        }        public ActionResult Report()        {            using (DataContext db = new DataContext())            {                var v = db.Contacts.ToList();                return View(v);            }        }
        public ActionResult GenerateReport(string typeOfReport)        {
            LocalReport lr = new LocalReport();            string path = Path.Combine(Server.MapPath("~/Report"), "MyFirstReport.rdlc");            if (System.IO.File.Exists(path))            {                lr.ReportPath = path;            }            else            {                return View("Index");            }            List<Contact> cm = new List<Contact>();            using (DataContext dc = new DataContext())            {                cm = dc.Contacts.ToList();            }            ReportDataSource rd = new ReportDataSource("APCRUDDataSet",cm);            lr.DataSources.Add(rd);            string reportType = typeOfReport;            string mimeType;            string encoding;            string fileNameExtension;            string deviceInfo =
                "<DeviceInfo>" +
                "<OutputFormat>" + typeOfReport + "</OutputFormat>" +
                "<PageWidth>8.5in</PageWidth>" +
                "</DeviceInfo>";
            Warning[] warning;            string[] streams;            byte[] renderedBytes;
            renderedBytes = lr.Render(                reportType,                deviceInfo,                out mimeType,                out encoding,                out fileNameExtension,                out streams,                out warning);
            return File(renderedBytes, mimeType); ;        }    }}
```

**9).** Create a view for Report method via right click.

```
@model IEnumerable<MvcApplication15.Contact>@{    ViewBag.Title = "Report";}<h2>Report</h2><table>    <tr>        <th>            Name        </th>        <th>            Mobile        </th>        <th>            Address        </th>    </tr>@foreach (var item in Model) {    <tr>        <td>            @Html.DisplayFor(modelItem => item.Name)        </td>        <td>            @Html.DisplayFor(modelItem => item.Mobile)        </td>        <td>            @Html.DisplayFor(modelItem => item.Address)        </td>    </tr>}</table><div style="padding:10px; border:1px solid black">    <div><a href="@Url.Action("GenerateReport", new {typeOfReport="PDF"})">Get Report PDF</a></div>    <div><a href="@Url.Action("GenerateReport", new {typeOfReport="EXCEL"})">Get Report EXCEL</a></div>    <div><a href="@Url.Action("GenerateReport", new {typeOfReport="WORD"})">Get Report WORD</a></div>    <div><a href="@Url.Action("GenerateReport", new {typeOfReport="IMAGE"})">Get Report IMAGE</a></div></div>
```

**10).** Add link button on **_Layout.cshtml** page

![RDLC report in MVC application](https://www.mindstick.com/mindstickarticle/36448269-c978-4c7c-8259-d7b0ad137421/images/0e74f87e-6d67-4d00-b540-19dcab269ef1.png)

Thank you for reading this Article, I hope it'll help you.

\

\

---

Original Source: https://www.mindstick.com/articles/23249/rdlc-report-in-mvc-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
