2014-05-05 256 views
-1

我想在MVC 4應用程序中以網頁形式顯示RDLC報表。我沒有得到任何適當的文件。任何人都可以請指導我如何在MVC 4中的網頁中顯示RDLC報告? RDLC報告是數據綁定的,其中很少有嵌套報告。使用報表查看器在MVC 4中顯示RDLC報告

+0

的ReportViewer需要視圖狀態,這樣的概念在MVC不復存在 – meda

+0

@m eda那麼,我如何使用它?有沒有其他方法? –

+0

檢查此http://stackoverflow.com/a/7176529/1880431有一些替代方案,他們需要一些工作 – meda

回答

-1

第6步:添加報告文件(.rdlc)並設計您的報告。 在本例中,我添加了一個用於存儲.rdlc文件的文件夾命名爲「RPTReports」 右鍵單擊報告文件夾>添加>新建項目>選擇報告下的報告>輸入報告文件名稱>添加。

步驟7:將視圖(aspx)添加到共享文件夾 轉到文件夾視圖>共享並右鍵單擊文件夾>添加>查看...>輸入視圖名稱>選擇ASPX(C#)視圖引擎>添加。

步驟8:添加asp.net控制的ScriptManager和的ReportViewer在View(CSS)用於顯示報表查看器 編寫以下代碼視圖(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> 

第11步:創建視圖

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

在這裏你可以得到工作downloadable source code

+4

這不是錯過了幾個步驟? – spenibus

+0

請注意,如果您想宣傳自己的產品/博客,您必須披露您的關聯**,否則您的答案可能被標記爲垃圾郵件。請閱讀[如何不成爲垃圾郵件發送者](https://stackoverflow.com/help/promotion) – DavidPostill

相關問題