-1

I want to display RDLC report in web form in MVC 4 application. I am not getting any proper documents for the same. Can anyone please guide me how can I show RDLC report in web page in MVC 4? The RDLC reports are data bound and few of them have nested reports.

tereško
  • 58,060
  • 25
  • 98
  • 150
Microsoft Developer
  • 5,229
  • 22
  • 93
  • 142
  • reportViewer requires viewstate, such notion no longer exist in MVC – meda May 05 '14 at 12:10
  • @meda So How can I work with it? Is there any other way? – Microsoft Developer May 05 '14 at 12:28
  • check this http://stackoverflow.com/a/7176529/1880431 there are some alternative they require some work – meda May 05 '14 at 12:30
  • 1
    Possible duplicate of [How can I use a reportviewer control in an asp.net mvc 3 razor view?](http://stackoverflow.com/questions/6144513/how-can-i-use-a-reportviewer-control-in-an-asp-net-mvc-3-razor-view) – rene Mar 12 '17 at 08:38

1 Answers1

-1

Step-6: Add Report file(.rdlc) and Design your report. In this example I have added a folder for store .rdlc files Named "RPTReports" Right Click on report folder > Add > New item > Select Report under Reporing > Enter report file name > Add.

Step-7: Add a View (aspx) into the Shared Folder Go to the Folder Views > Shared and Right click on the Folder > Add > View... > Enter View Name > Select ASPX (C#) View Engine > Add.

Step-8: Add asp.net control ScriptManager and ReportViewer In the View (ASPX) for show Report Viewer Write the following code into the View (ASPX)

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>ReportViwer in MVC4 Application</title>    
    <script runat="server">
        void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<MVCReportViwer.Customer> customers = null;
                using (MVCReportViwer.MyDatabaseEntities dc = new MVCReportViwer.MyDatabaseEntities())
                {
                    customers = dc.Customers.OrderBy(a => a.CustomerID).ToList();
                    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/rptCustomer.rdlc");
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportDataSource rdc = new ReportDataSource("MyDataset", customers);
                    ReportViewer1.LocalReport.DataSources.Add(rdc);
                    ReportViewer1.LocalReport.Refresh();
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="false" SizeToReportContent="true">
        </rsweb:ReportViewer>        
    </div>
    </form>
</body>
</html>

Step 11: Create View

@{
    ViewBag.Title = "Index";
}
<h2>Our Customer List</h2>
@Html.Partial("ReportViwerASPX")

Here you can get working downloadable source code

spenibus
  • 4,339
  • 11
  • 26
  • 35
  • 4
    Isn't this missing a few steps ? – spenibus Oct 01 '15 at 09:29
  • Please note if you want to promote your own product/blog you **must disclose your affiliation**, otherwise your answer may be flagged as spam. Please read [How to not be a spammer](https://stackoverflow.com/help/promotion) – DavidPostill Mar 12 '17 at 08:48