原創|使用教程|編輯:鄭恭琳|2019-10-31 15:19:23.860|閱讀 270 次
概述:本示例說明了如何以不同的格式加載報表并在Flash查看器中顯示報表。可以使用以下格式存儲報表:報表模板(.mrt文件)、報表文檔(.mdc文件)、編譯后的報表類(.cs或.dll文件)。這些格式中的任何一種都可以加載并顯示在Flash報表查看器中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
立即點擊下載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();
}在下面的屏幕截圖中,您可以看到示例代碼的結果。

本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn