This example shows how to add custom function to the designer.

First, you need to add the StiMvcDesigner component to the view page. Also, you need to pass the StiMvcDesignerOptions object to the constructor. The minimum required options are two actions - GetReport and DesignerEvent:
@using Stimulsoft.Report.Mvc;

...

@Html.Stimulsoft().StiMvcDesigner(new StiMvcDesignerOptions()
{
    Actions =
    {
        GetReport = "GetReport",
        DesignerEvent = "DesignerEvent"
    }
})

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

The GetReport() action loads the report template and returns answer to the client part of the designer using the GetReportResult() static method. In the parameters of this method, the report object should be passed:
public ActionResult GetReport()
{
	var report = new StiReport();
	report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
	
	// Add System.Web.Mvc.dll library to the report references
	var assemblies = new string[report.ReferencedAssemblies.Length + 1];
	Array.Copy(report.ReferencedAssemblies, assemblies, report.ReferencedAssemblies.Length);
	assemblies[assemblies.Length - 1] = "System.Web.Mvc.dll";
	report.ReferencedAssemblies = assemblies;
	
	return StiMvcDesigner.GetReportResult(report);
}

Finally, we need to add custom function using AddFunction() method:
public static string MyFunc(string value)
{
	return value.ToUpper();
}
		
static DesignerController()
{
	var ParamNames = new string[1];
	var ParamTypes = new Type[1];
	var ParamDescriptions = new string[1];

	ParamNames[0] = "value";
	ParamDescriptions[0] = "Descriptions";
	ParamTypes[0] = typeof(string);

	// How to add my function
	StiFunctions.AddFunction(
	"MyCategory",
	"MyFunc",
	"MyFunc",
	"Description",
	typeof(DesignerController),
	typeof(string),
	"Return Description",
	ParamTypes,
	ParamNames,
	ParamDescriptions);
}
...

In the screenshot below you can see the result of the sample code:

Adding a Custom Function to the Designer

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.