This example shows how to create a report with the Business Objects collection. Business Objects is an object class data with which the data can be presented in different structures: tables, lists, arrays, etc. This example uses two variants of Business Objects - IEnumerable and ITypedList.

For example, create two different views - ViewIEnumerable and ViewITypedList. Each of these views has its own GetReport action handler. Also you need to define the ViewerEvent action:
@using Stimulsoft.Report.Mvc;

...

@Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
	Actions =
	{
		GetReport = "GetReportIEnumerable",
		ViewerEvent = "ViewerEvent"
	}
})

...

@Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
	Actions =
	{
		GetReport = "GetReportITypedList",
		ViewerEvent = "ViewerEvent"
	}
})

Also we need to add these actions in the controller. The GetReportIEnumerable action loads the IEnumerable report and register data for it. In a similar way, the GetReportITypedList action loads the ITypedList report and register data for it.

Before the transfer of the result to the client part of the viewer, call the CheckReference() specal method. This method adds a reference to the assembly of the current project in the report ReferencedAssemblies collection, it is necessary to access the business objects that are compiled in this application. Optionally, the business objects may be taken from another assembly:
public ActionResult GetReportIEnumerable()
{
	var report = new StiReport();
	report.Load(Server.MapPath("~/Content/Reports/BusinessObjects_IEnumerable.mrt"));
	report.RegData("EmployeeIEnumerable", CreateBusinessObjectsIEnumerable.GetEmployees());
	CheckReference(report);
	
	return StiMvcViewer.GetReportResult(report);
}

public ActionResult GetReportITypedList()
{
	var report = new StiReport();
	report.Load(Server.MapPath("~/Content/Reports/BusinessObjects_ITypedList.mrt"));
	report.RegData("EmployeeITypedList", CreateBusinessObjectsITypedList.GetEmployees());
	CheckReference(report);
	
	return StiMvcViewer.GetReportResult(report);
}

private void CheckReference(StiReport report)
{
	var assemblyName = Assembly.GetExecutingAssembly().ManifestModule.Name;
	var refs = new List<string>(report.ReferencedAssemblies);
	if (!refs.Contains(assemblyName))
	{
		refs.Add(assemblyName);
		report.ReferencedAssemblies = refs.ToArray();
	}
}

The ViewerEvent action handles all the viewer events (switching pages, zooming, printing, exporting, interactivity, etc.) and returns the answer to the client using the ViewerEventResult() static method:
public ActionResult ViewerEvent()
{
	return StiMvcViewer.ViewerEventResult();
}

Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen:

Using Business Objects in the Report

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.