Display RDLC reports in MVC 4 using report viewer

醉酒当歌 提交于 2019-12-10 12:24:33

问题


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.


回答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



来源:https://stackoverflow.com/questions/23472074/display-rdlc-reports-in-mvc-4-using-report-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!