I need to use sessio开发者_StackOverflow中文版n in my MVC 3 web app like I used to do in my old ASP.NET web app. I need to save some values, and then access it from any of my controllers and all other views.
Please give me a very simple example following the best practices.
I am new in MVC development and started with MVC 3.
You use session the same way you do in webforms.
In your controllers you can simply use the Session object. You could save the state of a model in Session and pass the result to your view.
Basic session usage remains same for both mvc and webforms.
In addition to that you have ViewData, ViewBag also to store between controller and view
Refer to this article for creating a helper class for using strongly typed sessions in mvc.
加载中,请稍侯......
精彩评论