Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hold a data object temporarily in MVC controller,MVC,MVC Controller temp storage

I have a object that i want to store for a moment. The object is in a controller for now, the controller will generate a view. A AJAX request is made from the view to next controller. For that moment i need the object previously stored. Previously, i used session and it worked well. But not sure it is the right thing to do. Is session the answer for this or is there anything else?

I have used cache also.but as per the cache concept.It will access for all the users.So one user data will be override to another.So the cached object data will be change for the same user.I need to handle the data storage for an particular user(Independent).

How is it possible? anyother approach is there please share me.

In Controller I have used Httpcontext.cache["key"]=dataset;

but some one suggested like this.but its not displaying

Explain:

In Controller: httpcontext.current.cache is not coming.

HttpContext.Currenthandler and HttpContext.Currentnotification properties only coming.So How can we handle the temp data storage in MVC.

Please help me.

like image 276
user2866079 Avatar asked Dec 25 '22 19:12

user2866079


1 Answers

You could use TempData if you want to store data for the next request only. If data should be accessible between multiple requests, then use Session. Here is short explanation of each one with examples.

like image 105
Alex Avatar answered Jan 12 '23 01:01

Alex