简体   繁体   中英

How to retain parameters for xtraReport with a dataset as the datasource

I have a devExpress xtraReport that is being supplied by a strongly typed dataset. As long as I'm hard coding two parameters into the Actions, it loads the data into the dataset and displays in the report. Once I try to make it pass the values from the main page down through the partial, it fails. My first attempt was to pass the parameters through the ViewBag, wasn't working, so switched to a model, still not working right.

main page controller

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);
}

main page cshtml - added in the EditorFor to make sure the model makes it there (it does). Have tried calling the Partial both with and without putting 'Model'

@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)

controller for the partial - this does not receive the data from the model and I don't understand why. The model is NOT null, all the values are 0 (zero).

[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");
}

The view for the partial

@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()

The data needs to persist through the partial both to load the note for viewing, but also for the export function.

What am I doing wrong, or is there another better way to do this?

Thanks, Dave K.

The settings.CallbackRouteValues object tells the DocumentViewer where to request the actual report, and it can take parameters. Unfortunately it will be a separate request, so you can't send your model, only simple values that can be passed as strings. In this example , they are using a custom model for the report, but the model has to be re-created from raw values in each action.

If you convert your partial action to take integer parameters:

public ActionResult _SubsequentVisitReport(int noteType, int noteId)

you should be able to tack those arguments on the end of the CallbackRouteValues:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM