This example shows how to perform the required actions before printing or exporting the report in the viewer.

First you need to add the StiNetCoreViewer component to the view page. Also you need to pass the StiNetCoreViewerOptions object to the constructor. In the options you should set the next actions: GetReport, PrintReport, ExportReport and ViewerEvent. The last two actions will be called accordingly at report printing and exporting:
@using Stimulsoft.Report.Mvc;

...

@Html.StiNetCoreViewer(new StiNetCoreViewerOptions()
{
	Actions =
	{
		GetReport = "GetReport",
		PrintReport = "PrintReport",
		ExportReport = "ExportReport",
		ViewerEvent = "ViewerEvent"
	}
})

In the options above we define several actions, and we need to add it to the method.

The OnPostGetReport action loads the report and returns the answer to the client part of the viewer using the GetReportResult() static method. In the parameters of this method, the report object should be passed:
public IActionResult OnPostGetReport()
{
	// Create the report object
	var report = new StiReport();
	report.Load(StiNetCoreHelper.MapPath(this, "Reports/TwoSimpleLists.mrt"));

	return StiNetCoreViewer.GetReportResult(report);
}

The OnGetViewerEvent action handles all the viewer events (switching pages, zooming, etc.) and returns the answer to the client using the ViewerEventResult() static method:
public IActionResult OnGetViewerEvent()
{
	return StiNetCoreViewer.ViewerEventResult(this);
}

public IActionResult OnPostViewerEvent()
{
	return StiNetCoreViewer.ViewerEventResult(this);
}

The OnPostPrintReport action will be invoked when you print the report through menu of the viewer. In this action, you can get the report object and perform any action, for example connect to data. To prepare the answer for the client you should use the PrintReportResult() static method:
public IActionResult OnPostPrintReport()
{
	var report = StiNetCoreViewer.GetReportObject(this);
	
	// Some actions with report when printing
	
	return StiNetCoreViewer.PrintReportResult(this, report);
}

The OnPostExportReport action will be invoked when you export the report in any format through menu of the viewer. You can get the report object and perform any action. Also you can get the action parameters of the viewer and, for example, perform some action at the PDF report export. To prepare the answer for the client, you should use the ExportReportResult() static method:
public IActionResult OnPostExportReport()
{
	var report = StiNetCoreViewer.GetReportObject(this);
	var parameters = StiNetCoreViewer.GetRequestParams(this);

	// Some actions with report when exporting
	report.ReportName = "MyReportName";
	report.ReportAlias = report.ReportName;

	if (parameters.ExportFormat == StiExportFormat.Pdf)
	{
		// Change some export settings when exporting to PDF
		var settings = (StiPdfExportSettings)StiNetCoreViewer.GetExportSettings(this);
		settings.CreatorString = "My Company";

		return StiNetCoreViewer.ExportReportResult(this, report, settings);
	}
            
	return StiNetCoreViewer.ExportReportResult(this, report);
}

На скриншоте ниже Вы можете увидеть результат выполнения данного кода:

Managing Report Printing and Exporting

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.