原創(chuàng)|使用教程|編輯:鄭恭琳|2019-10-31 14:25:12.763|閱讀 289 次
概述:本示例說明如何加載不同格式的報表并在查看器中顯示??梢允褂靡韵赂袷酱鎯蟊恚簣蟊砟0澹?mrt文件)、報表文檔(.mdc文件)、編譯后的報表類(.cs或.dll文件)。這些格式中的任何一種都可以加載并顯示在報表查看器中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
立即點擊下載Stimulsoft Reports.Net最新版
本示例說明如何加載不同格式的報表并在查看器中顯示??梢允褂靡韵赂袷酱鎯蟊恚簣蟊砟0澹?mrt文件)、報表文檔(.mdc文件)、編譯后的報表類(.cs或.dll文件)。這些格式中的任何一種都可以加載并顯示在報表查看器中。
首先,您需要將StiMvcViewer組件添加到視圖頁面。您還需要將StiMvcViewerOptions對象傳遞給構造函數(shù)。所需的最少選項是兩個操作——GetReport和ViewerEvent,它們位于操作“Actions”選項組中。
@using Stimulsoft.Report.Mvc; ... @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", ViewerEvent = "ViewerEvent" } })
要演示不同格式的加載報表,請在網頁上添加鏈接。使用鏈接中的id參數(shù)報表定義。
<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().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", ViewerEvent = "ViewerEvent" } }) </td> </tr> </table>
在上面的選項中,我們定義了兩個動作,我們需要將其添加到控制器中。
GetReport操作根據(jù)URL的id參數(shù)加載報表,并使用GetReportResult()靜態(tài)方法將答案返回給查看器的客戶端部分。在此方法的參數(shù)中,應傳遞報表對象。
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 StiMvcViewer.GetReportResult(report); }
ViewerEvent操作處理所有查看器事件(切換頁面、縮放、打印、導出、交互等),并使用ViewerEventResult()靜態(tài)方法將答案返回給客戶端。另外,此操作還用于加載查看器組件的腳本。
public ActionResult ViewerEvent() { return StiMvcViewer.ViewerEventResult(); }
在下面的屏幕截圖中,您可以看到示例代碼的結果。
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn