【问题标题】:How to retain parameters for xtraReport with a dataset as the datasource如何以数据集为数据源保留 xtraReport 的参数
【发布时间】:2014-05-17 21:27:40
【问题描述】:

我有一个由强类型数据集提供的 devExpress xtraReport。只要我将两个参数硬编码到操作中,它就会将数据加载到数据集中并显示在报告中。一旦我尝试让它从主页向下通过部分传递值,它就会失败。我的第一次尝试是通过 ViewBag 传递参数,不工作,所以切换到模型,仍然不能正常工作。

主页控制器

public ActionResult SubsequentVisitReport(int noteType = 1, int noteId = 9)
{
  ViewBag.noteType = noteType;
  ViewBag.noteId = noteId;

  ReportParameters reportParamters = new ReportParameters();
  reportParamters.noteType = noteType;
  reportParamters.noteId = noteId;

  return View(reportParamters);
}

主页 cshtml - 添加到 EditorFor 以确保模型在那里(确实如此)。尝试在有和没有放置“模型”的情况下调用 Partial

@model ReportParameters
@Html.EditorFor(m => m.noteId)
@Html.EditorFor(m => m.noteType)

@Html.HiddenFor(m => m.id)
@Html.HiddenFor(m => m.noteType)
@Html.HiddenFor(m => m.noteId)

@Html.Partial("_SubsequentVisitReport", Model)

部分控制器 - 这不接收来自模型的数据,我不明白为什么。模型不为空,所有值为 0(零)。

[HttpPost]
public ActionResult _SubsequentVisitReport(ReportParameters model)
{
    int noteType = model.noteType;
    int noteId = model.noteId;

    rptSubsequentVisit report = new rptSubsequentVisit();
    try { report.DataSource = getSubsequentVisitData(model.noteType, model.noteId).Tables[0]; }
    catch { return RedirectToAction("Not_Authorized"); }
    ViewData["Report"] = report;
    return PartialView("_SubsequentVisitReport");
}

局部视图

@model ReportParameters

@Html.HiddenFor(m => m.id)
@Html.HiddenFor(m => m.noteType)
@Html.HiddenFor(m => m.noteId)

@Html.DevExpress().DocumentViewer(settings =>
    {
        // The following settings are required for a Report Viewer.
        settings.Name = "reportViewer1";
        settings.Report = (rptSubsequentVisit)ViewData["Report"];
        // Callback and export route values specify corresponding controllers and their actions.
        // These settings are required as well.
        settings.CallbackRouteValues = new { Controller = "Reports", Action = "_SubsequentVisitReport"};
        settings.ExportRouteValues = new { Controller = "Reports", Action = "_SubsequentVisitReportExport" };
    }).GetHtml()

数据需要通过partial持久化,既可以加载note进行查看,也可以用于导出功能。

我做错了什么,或者还有其他更好的方法可以做到这一点吗?

谢谢, 戴夫·K。

【问题讨论】:

  • 你最终解决了这个问题吗?我也在做同样的事情。
  • 嘿,是的,我确实想通了,在 Dev express 上来回转了几次。忘了我这里放了。会将您的答案标记为答案。

标签: c# devexpress asp.net-mvc-5 xtrareport


【解决方案1】:

settings.CallbackRouteValues 对象告诉 DocumentViewer 在哪里请求实际报告,它可以接受参数。不幸的是,这将是一个单独的请求,因此您无法发送模型,只能发送可以作为字符串传递的简单值。在this example 中,他们为报告使用自定义模型,但必须根据每个操作中的原始值重新创建模型。

如果您将部分操作转换为采用整数参数:

public ActionResult _SubsequentVisitReport(int noteType, int noteId)

您应该能够在 CallbackRouteValues 的末尾添加这些参数:

settings.CallbackRouteValues = new { Controller = "Reports", 
                                     Action = "_SubsequentVisitReport",
                                     noteType = model.noteType,
                                     noteId = model.noteId};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多