I need to pass data from one view to another in MVC 4.0. I am new to MVC 4.0.
The scenario is that I have a View in which a combo box is populated when the view gets loaded. I have a form on this view and on submission of this form I need to do some processing and accordingly show some status message on the View.
Since HTTP is stateless protocol the data (with which combo box got populated) gets lost. I want to retain this data as I don’t want to do same processing again and again to fetch the data.
Please suggest me how can I proceed?
In MVC (although I don’t think exclusively) you can use the
Sessionclass to store variables across multiple views.You can add an object to the
Sessionarray as a key/value pair withSession.Add(), and you can access the data via either an index, or the key.You can also add a variable by simply accessing the
Sessionindex with either the index or the key, regardless of whether you’ve explicitly added it to the array. So you can doSession[0] = new Object();orSession["object"] = new Object();because they have overridden the accessor property.I would recommend however that you do some research into proper use of the
Sessionarray.