session managment in mvc
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.
精彩评论