开发者

session managment in mvc

开发者 https://www.devze.com 2023-03-03 01:14 出处:网络
I have a menu on a shared view and on click of menu ite开发者_Python百科m i have to set a value in session or any object that i need on other view page. I am using MVC architecture usging razor. Pleas

I have a menu on a shared view and on click of menu ite开发者_Python百科m i have to set a value in session or any object that i need on other view page. I am using MVC architecture usging razor. Please help with your answer. Thanx..


You could store the object in the session in the controller action rendering the view. This way when you click on the menu link and get redirected to another controller action you will be able to fetch this object that was previously stored from the session.


You can use Session at razor view by writing session within code block.

e.g.

@{ 
     Session["uname"] = "somevalue"; 
}

but there are some more options available in mvc, that you should try viewdata, viewbag and tempdata.

0

精彩评论

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

关注公众号