StiMvcViewer with filters

Stimulsoft Reports.WEB discussion
Post Reply
Carlo
Posts: 5
Joined: Tue Apr 18, 2017 9:23 am

StiMvcViewer with filters

Post by Carlo »

Greetings. We're trying to understand how the "StiMvcViewer" should be used in a context where, before generating the report, the user can filter the relevant data (the data which will be used to generate the report) through some input fields (dropdowns, textfields..). When the user clicks the submit button, he's sent to the same page (or a different page..) where he still has all the input fields with the selected values, and below he can see the requested report thorugh the Mvc Viewer. If he decides to generate a new report, he should be able to change the values of the selected filters and click the submit button once more to regenerate the report. Here's the current code, with comments to highlight the issues we're facing:

CONTROLLER

//1) When the user first reaches this page, he can filter out
//some data through the use of several input fields. When
//he selected the desired filters, he clicks the submit button

public ActionResult Index()
{
FilterKaizenDto filters = new FilterKaizenDto();
_kaizenServ.RefreshFilterDatasources(filters);
return View(filters);
}

//2) when the submit button is pressed, the selected filters
//are sent to the Controller. According to the filters the relevant
//data are extracted from the database and the report is generated.
//Unfortunately, according to documentation here we here we have
//to return "StiMvcViewer.GetReportSnapshotResult(report);"
//but this causes the View to throw an exception because the model
//representing the filters ("input" in this context) is not sent again
//to the view. IDEALLY WE WOULD LIKE TO CREATE A MODEL WHICH CONTAINS BOTH THE FILTERS
//AND THE LIST OF OBJECTS USED TO GENERATE THE REPORT ("listaReportoKaizenDto" in this context)
//SO THAT WHEN THIS ACTION RETURNS THE REPORT IS DISPLAYED AS WELL AS THE FILTERS FIELDS

[HttpPost]
public ActionResult Index(FilterKaizenDto input)
{
IList<KaizenDto> listKaizen = _kaizenServ.Get(input);

_kaizenServ.RefreshFilterDatasources(input);

List<ReportKaizenDto> listaReportKaizenDto = listKaizen.GroupBy(p => p.Tipo, (key, g) => new ReportKaizenDto { Tipo = key, QuantitaPerTipo = g.Count() }).ToList();
try
{

// Creazione report con load del file .mrt
StiReport report = new StiReport();
report.Load(Server.MapPath("~/Content/ReportPerTipiKaizen.mrt"));


//.. caricamento dati
report.RegData("ReportKaizenDto", listaReportKaizenDto);
report.Compile();

return StiMvcViewer.GetReportSnapshotResult(report);
}
catch (Exception ex)
{
return null;
//return File(Encoding.ASCII.GetBytes(ex.Message), "text/plain");
}

}

public ActionResult ViewerEvent()
{
return StiMvcViewer.ViewerEventResult();
}

VIEW

@using TRIM.GestioneKaizen.Core.Dto;
@using Stimulsoft.Report.Mvc;
@model FilterKaizenDto

@{
ViewBag.Title = "Report e statistiche";
}

<div id="pulsantiAnagrafica">
@using (Html.BeginForm())
{
<div style="text-align:left;">
@Html.EditorFor(m => m)
<div style="display:inline-block; width:150px; vertical-align:top; margin-top:7px;">
@Html.EJ().Button("Submit").Size(ButtonSize.Large).Text("Genera report").Width("150").ContentType(ContentType.TextAndImage).PrefixIcon("e-search").CssClass("blueButton")
</div>
</div>
}</div>


@Html.Stimulsoft().StiMvcViewer("MvcViewer1",
new StiMvcViewerOptions()
{
Actions=
{
GetReportSnapshot="Index",
ViewerEvent = "ViewerEvent"
}
})

Thanks for the kind help, we'll wait for your feedback
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: StiMvcViewer with filters

Post by Alex K. »

Hello,

Please try to use the following:
- set the PassFormValues option to True.
- get parameters collection in any action of the viewer with GetFormValues() method

Code: Select all

@Html.Stimulsoft().StiMvcViewer("MvcViewer1", new StiMvcViewerOptions()
{
    Server =
    {
        PassFormValues = true
    },
...
}

public ActionResult GetReportSnapshot()
{
NameValueCollection formValues = StiMvcViewer.GetFormValues();
...

return StiMvcViewer.GetReportSnapshotResult(report);
}
https://www.stimulsoft.com/en/documenta ... ethods.htm

Thank you.
Post Reply