2012-04-25 19 views
2

私はasp.netのレポートビューアを使用してレポートを作成しました。今私はそれもMVC 3で作成したいと思います。私はMVCにとって非常に新しいので、あなたからの指導を期待してください。ありがとう!!!MVC 3でレポートビューアを使用してレポートを生成する方法は?

+3

私がこの[質問] [1]の重複であると考えています。 [1]:http://stackoverflow.com/questions/6144513/how-can-i-use-a-reportviewer-control-in-an-asp-net-mvc-3-razor-表示 –

+0

ありがとうKevin ...私はこの1つを試みたが、まだ私は問題に直面している... –

+0

レポート処理中にエラーが発生しました。 studentdataset(私のデータセット) pleaz助けてください –

答えて

0

実行時にデータセットを別々に設定し、それをレポートに関連付ける必要があります。

レポートウィザードを使用して最初にレポートを作成した場合は、使用できるデータセット定義(StudentDataSource.xsd)が作成されているはずです。このファイルを開くと、クエリのTableAdapterとともにクエリが表示されます。ここで

は...ケビンは、上記に言及質問(How can I use a reportviewer control in an asp.net mvc 3 razor view?

AデフォルトDATASET1データセットと生成さStudentDataSet.xsdとStudentReport.rdlc報告書に基づいて、例です

ここで修正されPDFController内のファイル()アクションメソッド:

public FileResult File() { 
     // Create a new dataset 
     StudentDataSet ds = new StudentDataSet(); 

     // Create and fill the Student data table 
     // using the Student table adapter 

     StudentDataSetTableAdapters.StudentTableAdapter dta = 
       new StudentDataSetTableAdapters.StudentTableAdapter(); 
     dta.Fill(ds.Student); 

     // Create a new report datasource with 
     //  Name = the dataset name in the report, 
     //  Value = the populated data table. 

     ReportDataSource rds = new ReportDataSource(); 
     rds.Name = "DataSet1"; 
     rds.Value = ds.Student; 

     ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer(); 
     rv.ProcessingMode = ProcessingMode.Local; 
     rv.LocalReport.ReportPath = Server.MapPath("~/Reports/StudentReport.rdlc"); 

     // Add the new report datasource to the report. 
     rv.LocalReport.DataSources.Add(rds); 

     rv.LocalReport.Refresh(); 

     byte[] streamBytes = null; 
     string mimeType = ""; 
     string encoding = ""; 
     string filenameExtension = ""; 
     string[] streamids = null; 
     Warning[] warnings = null; 

     streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 

     return File(streamBytes, mimeType, "StudentReport.pdf"); 
    } 

また、注意して、あなたは前の質問、YからASPXView.aspxページに、この同じコードを使用している場合MVCプロジェクトと使用しているデータセットテーブルアダプタの両方の名前空間をインポートする必要があります。

ASPXView.aspx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> 
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> 
<%@ Import Namespace="ProjectNamespace" %> 
<%@ Import Namespace="ProjectNamespace.StudentDataSetTableAdapters" %> 

<!DOCTYPE html> 

<html> 
<head id="Head1" runat="server"> 
    <title>ASPXView</title> 
</head> 
<body> 
    <div> 
     <script runat="server"> 
      private void Page_Load(object sender, System.EventArgs e) 
      { 
       StudentDataSet ds = new StudentDataSet(); 

       StudentTableAdapter dta = new StudentTableAdapter(); 
       dta.Fill(ds.Student); 

       ReportDataSource rds = new ReportDataSource(); 
       rds.Name = "DataSet1"; 
       rds.Value = ds.Student; 
       ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/StudentReport.rdlc"); 
       ReportViewer1.LocalReport.DataSources.Add(rds); 
       ReportViewer1.LocalReport.Refresh(); 
      } 
     </script> 
     <form id="Form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server">   
     </asp:ScriptManager> 
     <rsweb:reportviewer id="ReportViewer1" runat="server" height="500" width="500" AsyncRendering="false"></rsweb:reportviewer> 
     </form>   
    </div> 
</body> 
</html> 
関連する問題