ASP.NET MVC3 Webアプリケーションを構築しています。Crystalレポートを使用してレポートを作成し、Crystalレポートビューアを使用して表示する必要があります。 ウェブを検索したところ、MVC3 Webアプリケーションでそれを行うための強固な方法が見つかりませんでした。 これを行う方法に関するヒントやアイデアはありますか?MVC3を使用したCrystal Reportsビューア
答えて
ハッキングを気にしない場合は、実際にはかなり簡単です。 (CR4VS2010と仮定)
まず、Webフォームページをプロジェクトに追加し、Crystalレポートビューアコントロールを追加します。
CrystalDescisions.CrystalReports.Engine
、 CrystalDescisions.ReportSource
、 CrystalDescisions.Shared
、 とCrystalDescisions.Web
:
が、それはへの参照を追加したことを確認します。
次に、PageRouteをアプリケーションに追加して、新しく追加されたページにつなぎます。
最後に、これは「BLANK」の最大の痛みでした.CrystalのImage Handlerを動作させる必要があります。多くのはずな方法は、それらのどれもが本当に私のために働いていないので、私は不正行為に頼っ、ネットを中心にして、ここでSOの両方で、あります
public class CrystalImageHandlerController : Controller
{
//
// GET: /CrystalImageHandler.aspx
public ActionResult Index()
{
return Content("");
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
var handler = new CrystalDecisions.Web.CrystalImageHandler();
var app = (HttpApplication)filterContext.RequestContext.HttpContext.GetService(typeof(HttpApplication));
if (app == null) return;
handler.ProcessRequest(app.Context);
}
}
これはどこで、/CrystalReportsImageHandler.aspxとしてこのコントローラへのルートを追加します。 CRはそれがハンドラであることを期待しています。これはエリアでも使用でき、必要に応じてハンドラとページルートを変更するだけです。
あなたの剃刀レイアウトを使用することはできません。視覚的な連続性を得るには、他の手段に頼る必要があります。 (IFrameを使用しました)
私たちのプロジェクトでは、レポートをPDF形式で直接返しています。主に同じプロジェクトでWebFormsとMVCの両方を使用しないことを決めました。なぜなら、主にコードベースをきれいにするためです。
レポートは、手動で作成されたデータと、NHibernateで必要とされるすべての情報を取得するサービスクラスによって埋められたデータで生成されます(ORM永続性とDB抽象化のレイヤーを使用しているため、Crystal Reportsデータベースに直接接続してはいけません)。
プロジェクトが「プレビューモード」などのブラウザでレポートを表示する必要がない場合は、ここで私はこのような状況のために書いたカスタムのActionResultです:クリスタルレポートので
public class PdfReportResult : ViewResult
{
/// <summary>
/// Crystal Report filename
/// </summary>
public string reportFileName { get; set; }
/// <summary>
/// DataSet used in the report
/// </summary>
public DataSet reportDataSet { get; set; }
/// <summary>
/// Report parameters
/// </summary>
IDictionary<string, object> parameters { get; set; }
public PdfReportResult(string reportFileName, DataSet reportDataSet, IDictionary<string, object> parameters)
{
if (string.IsNullOrEmpty(reportFileName))
throw new ArgumentException("Report filename not informed", "reportFileName");
if (reportDataSet == null)
throw new ArgumentException("DataSet not informed", "reportDataSet");
if (parameters == null)
this.parameters = new Dictionary<string, object>();
else
this.parameters = parameters;
this.reportDataSet = reportDataSet;
this.reportFileName = reportFileName;
}
public PdfReportResult(string reportFileName, DataSet reportDataSet)
: this(reportFileName, reportDataSet, null)
{ }
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
if (string.IsNullOrEmpty(this.ViewName))
this.ViewName = context.RouteData.GetRequiredString("action");
// Alias to make the code more legible
HttpResponseBase response = context.HttpContext.Response;
// Generating the report
using (ReportDocument report = new ReportDocument())
{
// Load the report
report.Load(context.HttpContext.Server.MapPath("~/Reports/" + reportFileName));
// Set the dataset
report.SetDataSource(reportDataSet);
// Set the parameters (if any)
foreach (var parameter in parameters)
report.SetParameterValue(parameter.Key, parameter.Value);
// Send back the PDF to the user
using (MemoryStream oStream = (MemoryStream)report.ExportToStream(ExportFormatType.PortableDocFormat))
{
response.Clear();
response.Buffer = true;
response.AddHeader("Content-Disposition", this.ViewName + ".pdf");
response.ContentType = "application/pdf";
response.BinaryWrite(oStream.ToArray());
response.End();
}
}
}
}
は、サーバーコントロールである場合、レポートを表示するにはWebページ/ユーザーコントロールが必要です。そして、このwebform/user controlをmvcのviewsフォルダの中に置かないと、CrViewerの404で壊れたボタンが表示されます。また、剃刀ビューでIframeを使用してレポートを表示することもできます。以下は作業モデル[VS2010]です。
ステップ1:Crystalレポートの設定
1. Webサイトのルートディレクトリに最上位のフォルダを作成します。
2. Crystalレポート.rptファイルをこのフォルダに入れます。
3.このフォルダにWebページ(.aspx)を追加します。このページはレポートビューアページとして機能します。このページにCrystalReportViewerコントロールを追加します。
4.アセンブリの登録は、aspxページの上部に追加されます。
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>.
のCrystalReportViewerのバージョンを確認してください。このためには、VSサイドバーのツールボックスから「項目を選択」を選択します。このバージョンとCrystalDecisions.Webバージョンをaspxページの上に比較してください。両方が同じ場合はそのままにしてください。そうでない場合は、CRViewerと同じアセンブリ登録バージョンを変更してください。
ウェブサイトルートフォルダの下のweb.configファイルに移動します。タグの下の 'CrystalDecisions'で始まるアセンブリをチェックしてください。 CrystalReportViewerバージョン(ここではVersion = 13.0.2000.0)と同じバージョンを変更してください。
ステップ2:コントローラの設定、アクション&ビュー
1.レポートのコントローラクラスで新しいアクションを追加します。
2.データベース/ファイルからデータをロードするために必要な手順を記述します。
3.データをセッションに設定します。
4.この操作のビューを追加しないでください。代わりにResponse.Redirectメソッドを使用します。
public class ReportController : Controller
{
public ActionResult reportView(string id)
{
Session["ReportSource"] = GetdataFromDb();
Response.Redirect("~/Reports/WebForm1.aspx");
return View();
}
}
.aspxページにページロードイベントを追加します。
protected void Page_Load(object sender, EventArgs e) { CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(Server.MapPath("~/Reports/CR_report.rpt")); report.SetDataSource(Session["ReportSource"]); crViewer.ReportSource =report; }
は、ステップ3:リトルを避けるためにGlobal.asaxの
1にハック「セッション状態はセッションIDを作成しましたが、応答がすでにによってフラッシュされたので、それを保存することはできませんアプリケーション "エラーまたは"空白の水晶レポートページ出力 "次のコードをGlobal.asaxに追加します。
void Session_Start(object sender, EventArgs e)
{
string sessionId = Session.SessionID;
}
今、あなたは、Crystalレポートを表示するには、ReportControllerでreportView()アクションを呼び出すことができます。
素敵な一日を!
- 1. asp.netビューアを使用したCrystal Reports/vs2010の表示問題
- 2. Crystal Reports、VB.netを使用したMultiThreading
- 3. Crystal Reportsを使用したWPFアプリケーション
- 4. Crystal ReportsはCrystal Reportsバージョン8を使用して
- 5. Crystal Reportsを使用する
- 6. Crystal Reports ReportDocumentを使用
- 7. Crystal Reports .Net WinFormsビューア - 完全な位置揃えを使用した壊れたアンダーライン
- 8. QuickBooks(QBW)ファイルを使用したSSRSまたはCrystal Reports?
- 9. Visual Studio 2010でCrystal Reports 2011を使用
- 10. Crystal Reports
- 11. Crystal Reportsを使用したClickOnceの前提条件
- 12. ASP.Netを使用したCrystal ReportsのBlobフィールド
- 13. MVC Crystal Reportビューア
- 14. C#オブジェクトでのCrystal Reportsの使用
- 15. ローカライズされたCrystal Reports
- 16. Crystal Reports ExportToDiskフォントサイズ
- 17. Crystal Reports MVVMデータソース
- 18. Crystal Reportsのベストプラクティス
- 19. Crystal Reportsのピボットテーブル?
- 20. Crystal Reports Cssクラス
- 21. C#/ Crystal Reportsエラー
- 22. Crystal Reportsセクションアレンジメント
- 23. Crystal Reports SDKエラー
- 24. DotNetNuke Crystal Reports
- 25. Crystal Reports用のMySQLのVB.NETアプリケーションでCrystal Reportsのログオン情報を尋ねる
- 26. Crystal Reportsを使用してバーコードを印刷
- 27. Crystal Reports、パラメータを使用してNULL値を受け入れる
- 28. Asp.netでCrystal Reportsを使用しているときの問題
- 29. Crystal Reportsを使用して印刷する方法
- 30. のCrystal Reportsを使用して同じデータ
ありがとうございます。私は[ここ](http://www.highoncoding.com/Articles/550_Creating_Crystal_Report_in_ASP_NET.aspx)からWebformの部分を取得し、それをあなたのコントローラと組み合わせて、私は自分のレポートを見ることができました。 –
素晴らしい!私はまた、このごちそうにあなたを有効にする必要があります:Webビューアを使用するときは、JS APIがブラウザにあります。ドキュメントは見つかりませんでしたが、iframeを使用して自分のサイトレイアウトで動作させると、サイズ変更の方法が非常に貴重であることがわかりました。オブジェクト名は _UIです。 –
あなたは「このコントローラにルートを/CrystalReportsImageHandler.aspxとして追加する」と言います。どのように私はこれを正確に行うのですか? –