开发者

How do I use ASP.NET Session object in my MVC 3 web app?

开发者 https://www.devze.com 2023-03-07 06:16 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号