SSRS Integration with Microsoft ASP.NET MVC 4 and Razor


[UPDATE: I have dumped SSRS, Click Here for details.]

This is a massive excerpt from

I will be rewriting this to meet my needs, and so that I don’t violate copyright. :)

There is a lot of code here that needs to be modified for this to follow a clean isolation, and adaptive layout.

View: ReportViewer.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ReportViewerControl.ascx.cs" Inherits="ReportViewerControl" %>
<%@ Register TagPrefix="rsweb" Namespace="Microsoft.Reporting.WebForms" Assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>

<form id="form1" runat="server">
<div style="Height:720px;Width:800px">
    <asp:ScriptManager ID="scriptManager" runat="server" ScriptMode="Release" EnablePartialRendering="false" />
    <rsweb:ReportViewer Width="100%" Height="100%" ID="reportViewer" ShowPrintButton="true" KeepSessionAlive="true" runat="server" AsyncRendering="false" ProcessingMode="Remote">
         <ServerReport />


    public partial class ReportViewerControl : System.Web.Mvc.ViewUserControl
        protected void Page_Init(object sender, EventArgs e)
            // Required for report events to be handled properly.
            //reportViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials();
            Context.Handler = Page;
        protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                ReportingServicesReportViewModel model = (ReportingServicesReportViewModel)Model;
                reportViewer.ServerReport.ReportServerCredentials = model.ServerCredentials;
                ReportParameter[] RptParameters = model.parameters;
                reportViewer.ServerReport.ReportPath = model.ReportPath;
                reportViewer.ServerReport.ReportServerUrl = model.ReportServerURL;                

                if(RptParameters.Count() > 0)


    public class ReportingServicesReportViewModel
        #region Constructor
        public ReportingServicesReportViewModel(String reportPath,List<ReportParameter> Parameters)
            ReportPath = reportPath;
            parameters = Parameters.ToArray();
        public ReportingServicesReportViewModel()
        #endregion Constructor

        #region Public Properties
        public ReportServerCredentials ServerCredentials { get { return new ReportServerCredentials(); } }
        public String ReportPath { get; set; }
        public Uri ReportServerURL { get { return new Uri(WebConfigurationManager.AppSettings["ReportServerUrl"]); } }
        public ReportParameter[] parameters { get; set; }
        private string UploadDirectory = HttpContext.Current.Server.MapPath("~/App_Data/UploadTemp/");
        private string TempDirectory = HttpContext.Current.Server.MapPath("~/tempFiles/");        

you can use like this in controller:


public class HomeController

    public ActionResult ActionReport(int Id)
      ReportingServicesReportViewModel model = new ReportingServicesReportViewModel(
      new List<Microsoft.Reporting.WebForms.ReportParameter>()
        new Microsoft.Reporting.WebForms.ReportParameter("parameter1",Id.ToString(),false) 
            return View("ViewReport", model);


@model ReportingInfrastructure.ReportingServicesReportViewModel
<div style="display: table; width: 100%;">
        @Html.Partial("ReportViewerControl", Model)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.