Wednesday, December 14, 2011

Using ReportViewer Control in ASP.NET MVC



Assembly References (From Visual studio2010 installation folder) :
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WebForms

Step 1 - Create a view called Report and bind it to strongly type ReportViewModel.


@model ReportViewModel
@{
ViewBag.Title = "Reports";
}

Reports: @Model.Title






Step 2 - Add a WebForm(ReportViewer.aspx) to your Web Project under a folder called Reports. It should have following html code in it.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="Sample.Web.Reports.ReportViewer" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>




















Code behind

public partial class ReportViewer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ReportName = Request.QueryString["Name"];
if (ReportName != null)
{
string ReportServerURL = Request.QueryString["ServerURL"];
if (ReportServerURL == null)
ReportServerURL = @"http://localhost/reportserver";

rptViewer.ShowParameterPrompts = true;
rptViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
rptViewer.ServerReport.ReportServerUrl = new Uri(ReportServerURL);
rptViewer.ServerReport.ReportPath = string.Format("/{0}", ReportName);
}
}
}

6 comments:

  1. Deba deserves credit for providing this information in a simplified way. Helped me migrate a report application from asp to MVC. Appreciate it isn't enough info for a ReportViewer beginner.

    ReplyDelete
  2. Thanks for sharing excellent informations. Your
    website is very cool.
    Premium

    ReplyDelete
  3. An iOS course provides step-by-step learning for mobile application creation. It covers core concepts with practical exercises. This ios course supports career advancement. It is effective.

    ReplyDelete
  4. Well written! Our java training online
    connects core concepts with practical development.

    ReplyDelete