I study asp. Net mvc and decided to try the trivial task.

  1. Print a two-dimensional array in the view.
  2. By pressing a button with it, for example, a transposition operation should be performed and instead of the current array, output a transposed array on the same page.

I brought the array through the viewbag, how to continue working with it? The variable i'm assigning to the controller becomes null

  • one
    Rumors about the "triviality" of the task turned out to be greatly exaggerated :). Please add code and markup to the question. - Igor
  • Unfortunately, now there is no possibility to add code, it will help me if you answer the question why if I create a global variable in the controller and assign it a value in one action method, then when I call it in another action method, its value becomes null? - Gabyan

1 answer 1

if I create a global variable in the controller and assign a value to it in one action method, then when I call it in another action method, its value becomes null ?

I am sure that a member of the controller class is hidden behind the name "global variable". For each request processed on the server, a new object (instance) of the controller is created, which does not know anything about the field values ​​of other controllers of the same type that worked before or in parallel processes other requests.