I'm trying to make an webApp and I have a conflict, because I have a model which I call in the controller, but everytime I change between views with the same controller the instance of my model resets and take the initial value again.
DataTable dt;
public AdminUsers()
{
dt = (new Userdb()).GetUsers();
}
public ActionResult Admin()
{
... // do whatever with dt before showing the results
return View(this.dt);
}
public ActionResult Results() // dt resets with the initial values
{
return View(this.dt);
}
How can I keep the values between views after the modification?
For this purpose you can use Session
Like that when you init it ( in your AdminUsers() method for example )
And then retrieve your value, but always check is the session is not null :