【发布时间】:2010-09-25 19:33:31
【问题描述】:
我知道在 ASP.NET MVC 中不允许使用服务器端控件,但是我们有一长串水晶报告,该公司已经为我想用于我们的以前的应用程序生成了这些报告新的 ASP.NET MVC 应用程序。
在 ASP.NET MVC 中是否有合适的方式使用水晶报表?如果有,怎么做?
【问题讨论】:
标签: asp.net-mvc crystal-reports
我知道在 ASP.NET MVC 中不允许使用服务器端控件,但是我们有一长串水晶报告,该公司已经为我想用于我们的以前的应用程序生成了这些报告新的 ASP.NET MVC 应用程序。
在 ASP.NET MVC 中是否有合适的方式使用水晶报表?如果有,怎么做?
【问题讨论】:
标签: asp.net-mvc crystal-reports
我们在工作中遇到过类似的情况。
我们使用的解决方案:
我们没有发现此设置有任何问题(除了普通的 Crystal 问题)。
【讨论】:
其实很简单。只需将以下引用添加到您的 MVC 项目:
使用 Action 方法如下:
C#:
using CrystalDecisions.CrystalReports.Engine;
public ActionResult Report()
{
ReportClass rptH = new ReportClass();
rptH.FileName = Server.MapPath("[reportName].rpt");
rptH.Load();
rptH.SetDataSource([datatable]);
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
VB.NET:
Imports CrystalDecisions.CrystalReports.Engine
Public Function Report() As ActionResult
Dim rptH As New ReportClass()
rptH.FileName = Server.MapPath("[reportName].rpt")
rptH.Load()
rptH.SetDataSource([datatable])
Dim stream As IO.Stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Return File(stream, "application/pdf")
End Function
【讨论】:
只需添加此参考:使用 CrystalDecisions.CrystalReports.Engine;
比做这个动作:
using CrystalDecisions.CrystalReports.Engine;
public ActionResult Report()
{
List<Table> table = new List<Table>();
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Repport/CrystalReport1.rpt")));
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "Suivie Historique.pdf");
}
【讨论】: