发布时间 : 2019-10-31 15:19:23.860|阅读 274 次
概述:本示例说明了如何以不同的格式加载报表并在Flash查看器中显示报表。可以使用以下格式存储报表:报表模板(.mrt文件)、报表文档(.mdc文件)、编译后的报表类(.cs或.dll文件)。这些格式中的任何一种都可以加载并显示在Flash报表查看器中。
相关链接:
立即点击下载Stimulsoft Reports.Net最新版
本示例说明了如何以不同的格式加载报表并在Flash查看器中显示报表。可以使用以下格式存储报表:报表模板(.mrt文件)、报表文档(.mdc文件)、编译后的报表类(.cs或.dll文件)。这些格式中的任何一种都可以加载并显示在Flash报表查看器中。
首先,您需要将StiMvcViewerFx组件添加到视图页面。另外,您需要将StiMvcViewerFxOptions对象传递给构造函数。所需的最少选项是GetReport和ViewerEvent操作。它们位于操作“Actions”选项组中。
@using Stimulsoft.Report.Mvc;
...
@Html.Stimulsoft().StiMvcViewerFx(new StiMvcViewerFxOptions()
{
Actions =
{
GetReport = "GetReport",
ViewerEvent = "ViewerEvent"
}
})要演示不同格式的加载报表,请在网页上添加链接。使用链接中的id参数报表定义。
<table>
<tr>
<td class="reports" valign="top">
<div style="width: 150px;">
@Html.ActionLink("Simple List", "Index", new { id = "1" })
<br />Report Snapshot
<br /><br />
@Html.ActionLink("Two Simple Lists", "Index", new { id = "2" })
<br />Report Template
<br /><br />
@Html.ActionLink("Master Detail", "Index", new { id = "3" })
<br />Compiled Report Class
<br /><br />
@Html.ActionLink("Selecting Country", "Index", new { id = "4" })
<br />Compiled Report Class
</div>
</td>
<td style="width: 100%;" valign="top">
@Html.Stimulsoft().StiMvcViewerFx(new StiMvcViewerFxOptions()
{
Actions =
{
GetReport = "GetReport",
ViewerEvent = "ViewerEvent"
}
})
</td>
</tr>
</table>接下来,我们需要在控制器中添加定义的动作。
GetReport操作将根据URL的id参数加载报表,并使用GetReportResult()静态方法将答案返回到Flash查看器的客户端。在此方法的参数中,应传递报表对象。
public ActionResult GetReport(int? id)
{
// Create the report object
StiReport report = new StiReport();
// Load report
switch (id)
{
// Load report snapshot
case 1:
report.LoadDocument(Server.MapPath("~/Content/Reports/SimpleList.mdc"));
break;
// Load report template
case 2:
report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
break;
// Load compiled report class
case 3:
report = new StiMasterDetail();
break;
// Load compiled report class
case 4:
report = new StiParametersSelectingCountryReport();
break;
// Load report snapshot
default:
report.LoadDocument(Server.MapPath("~/Content/Reports/SimpleList.mdc"));
break;
}
// Load data from XML file for report template
if (!report.IsDocument)
{
DataSet data = new DataSet("Demo");
data.ReadXml(Server.MapPath("~/Content/Data/Demo.xml"));
report.RegData(data);
}
return StiMvcViewerFx.GetReportResult(report);
}ViewerEvent操作处理所有查看器事件,并使用ViewerEventResult()静态方法将答案返回给客户端。此操作还用于加载查看器组件的脚本。
public ActionResult ViewerEvent()
{
return StiMvcViewerFx.ViewerEventResult();
}在下面的屏幕截图中,您可以看到示例代码的结果。

渝ICP备12000582号-15/渝公网安备 50010702501010号