将参数表格MVC传递给Stimulsoft报告

时间:2019-02-26 22:22:46

标签: asp.net model-view-controller stimulsoft

查看代码如下:

asdf
sadf
sadf
asdf
asdf

控制器代码如下:

@using Stimulsoft.Report.Mvc;
@using Stimulsoft.Report;

@{
    ViewBag.Title = "ListPouyaProject";
    Layout = "~/Views/Shared/_mainView.cshtml";
}

<section class="content">
    <!-- Default box -->
    <div class="box">
        <div class="box-body">
            <div class="form-group">
            Start Date: <input type="text" id="date1" name="date1" onclick="PersianDatePicker.Show(this, '1392/03/22');" />
           End Date : <input type="text" id="date2" name="date2" onclick="PersianDatePicker.Show(this, '1397/03/22');" />
            </div>
            <div class="form-group">
                @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
                {
                    Actions =
                    {
                        GetReport = "Report4_ListPouyaProject",
                        ViewerEvent = "ViewerEvent"
                    }
                })
            </div>
        </div>
    </div>
</section>

我想从视图中将public ActionResult Report4_ListPouyaProject() { var report = new StiReport(); report.Load(Server.MapPath("~/Content/Reports/ListPouyaProject.mrt")); return StiMvcViewer.GetReportResult(report); } public ActionResult ListPouyaProject() { return View(); } public ActionResult ViewerEvent() { return StiMvcViewer.ViewerEventResult(); } date1变量传递给控制器​​。

为此,我们需要将以下命令添加到contoroller中:

date2

如何将参数report.CompiledReport.DataSources["spm_report_4_ListPouyaProject"].Parameters["StartDate"].ParameterValue = DateTime.Parse(date1); report.CompiledReport.DataSources["spm_report_4_ListPouyaProject"].Parameters["EndDate"].ParameterValue = DateTime.Parse(date2); date1从视图传递到控制器?

1 个答案:

答案 0 :(得分:0)

首先,您需要将StiMvcViewer组件添加到视图页面。另外,您需要将StiMvcViewerOptions对象传递给构造函数。所需的最少选项是两个操作-GetReport和ViewerEvent,它们位于“操作”选项组中。

  @using Stimulsoft.Report.MVC;
    @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
        {
            Actions =
            {
                GetReport = "GetReport",
                ViewerEvent = "ViewerEvent"
            }
        })

    <div style="width: 150px;">
                    @Html.ActionLink("Simple List", "Index", new { id = "1" })
                    <br />Report Snapshot
                </div>

和控制:

public ActionResult GetReport(int? id)
    {
        // Create the report object
        StiReport report = new StiReport();
     switch (id)
{
    // Load report snapshot
    case 1:
        // Load report
         // Load report snapshot
               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);
    }
    public ActionResult ViewerEvent()
    {
        return StiMvcViewer.ViewerEventResult();
    }