Doubt with global variable in a controller

4

I have a method in my controller which is called through ajax. It populates a global variable within this controller .

Is there any way I can access this global variable already populated by the first method if I call another ajax method on the same page and controller ?

The end goal: This variable would be a large list of data that is randomly generated. So I want in the first method to generate. The person sees the data and if it gives the ok it returns to controller with that same data and does another action with them.

    
asked by anonymous 18.08.2015 / 19:42

2 answers

3

Unable to do by global variable.

For each request the controller is instantiated, then its global variable will lose the value.

A good practice to do this is through Session state or cookies .

One way to do this as a gambiarra is to make your global variable as static , but is not recommended to use a global changeable state in a web application.

    
18.08.2015 / 19:49
1

This is a great gambiarra. What you can do is install Redis and save this "status" per user on a key outside the ASP application .NET MVC.

Access to this variable is done by this client .

    
19.08.2015 / 02:17