This project has moved and is read-only. For the latest updates, please go here.


So you have a sweet ASP.NET MVC application and a set of awesome SSRS Reports that do all work for you. Next, you are wondering how to display them on your web project.

Before, with ASP.NET Web Forms was very easy just to add a ReportViewer control, configure it a little bit, and boom! reports ready. But with MVC thing's got a little complicated.

Lucky you, this guide will get you through the setup and visualization of your first report on MVC by using the ReportViewer for MVC library.

First things first, installing the library

In order to start, you'll need to install the ReportViewer for MVC package from NuGet. Run the following command in the package manager console:

PM> Install-Package ReportViewerForMvc

NuGet will take care of installing all necessary dependencies and files. Check the section Installation & Configuration for more details.

Let's start by configuring a ReportViewer on the Controller

One quick an easy way of using the ReportViewerForMvc library is by sending a ReportViewer object already configured to the View.

Configuring ReportViewer for Server Reports

First, let's reference the ReportViewer namespace Microsoft.Reporting.WebForms on your controller:

using Microsoft.Reporting.WebForms;

Second, we'll make a new instance of ReportViewer and configure it to use a report stored on SSRS on your controller Action:

ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Remote;

reportViewer.ServerReport.ReportPath = "/AdventureWorks 2012/Sales_by_Region";
reportViewer.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer/");

ViewBag.ReportViewer = reportViewer;


Uhmm… I have Client Report Definition (.rdlc) files, how do I run those?

Easy. Working with Local Reports is very straight forward and very similar to the example above. Check it out:

You know the drill, reference the ReportViewer namespace:

using Microsoft.Reporting.WebForms;

This time, create the instance of ReportViewer but configure it to process local reports and provide with the details instead:

ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;

reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\YourLocalReport.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dsLocalReport", dataSet.Tables["SampleTable"]));

ViewBag.ReportViewer = reportViewer;

Working the View with the ReportViewerForMvc helpers

Ok, so you have your report ready and you are ready to show it to your boss.

Open the view were you like to render the report and reference the ReportViewerForMvc namespace:

@using ReportViewerForMvc;

Use the built-in html helpers to render a report in your page:

@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)

Run your project and check the results. ReportViewerForMvc will render the report on a html iframe. It will also resize it to neatly display it on your page. You can change how the report is going to behave, check out ReportViewerForMvc public methods.

But wait, there’s more!

You can also render a report through an anonymous method helper included in the library.

Using anonymous on ReportViewerForMvc

If you like to use the anonymous methods helper you just need to call the Html.ReportViewer helper, send the correct parameters and you are ready to go. Check the complete View code below:

@model IEnumerable<ReportViewerForMvcSample.Models.Department>

@using ReportViewerForMvc

    ViewBag.Title = "Anonymous Sample";

<h2>Anonymous Sample</h2>

    new { ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local },
    new { ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\LocalReportSample.rdlc" },
    new { ReportTitle = "Local Report Sample" },
    new { Name = "dataSource", Value = Model },

So what’s next?

This guide has provided you with the basic structure for rendering reports on MVC. You can explore the full ReportViewer for MVC Documentation to learn about customizing the ReportViewer, configuring the helper and the library internals.

Last edited Mar 20, 2015 at 12:10 AM by armanio123, version 12