Which is the best method to temporary hold and access collection of data between one more controllers?
For example, view1.cshtml contain a grid with the following data items:
--------------------
Name | Address | Age
--------------------
aa | ad1 | 11
--------------------
bb | ad2 | 22
-------------------
cc | ad3 | 33
--------------------
and if a user selected first 2 rows, then the selected row items needs to be displayed in a grid on another another view named view2.cshtml. The user can go back to first view again and if select a new row item , then I want to to append the selected item too to the grid displayed on the second view.
I've tried ViewBag and TempData to temporarily store the data. But unfortunately the data getting cleared on sometimes. Which is the best option to solve this situation?
One way is to pass your object in the action like this:
The controller action method signature could be something like:
Another way is to store it in tempdata like this, and its once readable, after once read, it si automatically destroyed:
And in other controller action read it like this:
if you want it to be accessable after reading call this: