Accessing report's variables from the controller

Stimulsoft Reports.NET discussion
Post Reply
Evokati
Posts: 5
Joined: Mon Sep 23, 2024 8:39 am

Accessing report's variables from the controller

Post by Evokati »

So, I have a .net 6 MVC application.
I created a report with several variables. What I want to achieve is:
1. Display the report viewer to the user
2. Let him enter these variables (report parameters)
3. When he presses "Submit", I want to access the variables the user entered inside the controller and retrieve appropriate data
4. Display the report to the user.

How can I do that? Specifically, I don't understand how to access the report's variables from the controller.
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: Accessing report's variables from the controller

Post by Max Shamanov »

Hello,

Please check the following link with example project:
https://github.com/stimulsoft/Samples-R ... 0in%20Code

Thank you.
Evokati
Posts: 5
Joined: Mon Sep 23, 2024 8:39 am

Re: Accessing report's variables from the controller

Post by Evokati »

Yeah, I saw that already. But in this example the parameters are taken from a custom form and then assigned to the report. While I want to do kind of the opposite - get these parameters from the report after user entered them in the viewer and clicked submit.

sti viewer parameters.png
sti viewer parameters.png (11.11 KiB) Viewed 3234 times
Evokati
Posts: 5
Joined: Mon Sep 23, 2024 8:39 am

Re: Accessing report's variables from the controller

Post by Evokati »

Ok, I think I got it. I can use the ViewerInteraction action:

Code: Select all

public async Task<IActionResult> ViewerInteraction()
{
	StiRequestParams requestParams = StiNetCoreViewer.GetRequestParams(this);			

	if (requestParams.Action == StiAction.Variables)
	{
		var startDate = requestParams.Interaction.Variables["StartDate"];

		// Do something
	}

	return StiNetCoreViewer.InteractionResult(this);
}
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: Accessing report's variables from the controller

Post by Max Shamanov »

Hello,

Yes, you can try to use the viewer events.
Please check the following link with documentation:
https://www.stimulsoft.com/en/documenta ... meters.htm

Thank you.
JohnW
Posts: 113
Joined: Mon Nov 20, 2017 8:29 pm

Re: Accessing report's variables from the controller

Post by JohnW »

I don't know if this is helpful but can read them for the report dataset. I load the dataset into a datatable in code and then script out what I want to do. Once it is in the table you can do just about anything that may be needed.

Code: Select all

  Dim dt As DataTable = report.Dictionary.GetDataSet("newLicenseRpt").Tables(0)

John W
jessieleon
Posts: 1
Joined: Thu Oct 03, 2024 3:53 am

Re: Accessing report's variables from the controller

Post by jessieleon »

It helps me
Max Shamanov
Posts: 975
Joined: Tue Sep 07, 2021 10:11 am

Re: Accessing report's variables from the controller

Post by Max Shamanov »

Hello,

You are Welcome!
Post Reply