Reputation: 285
Can anyone tell me how to create Session Context in Mvc3 ? I am new in Mvc and want to know about How to create session and Syntaxes in Detail.
Thanks in advance.
Upvotes: 0
Views: 710
Reputation: 12904
Use the HttpContext
class to access Session
and more. You will not need to instantiate a session, this happens automatically. All you need to do is reference it in your code.
HttpContext.Current.Session["MyVariable"] = "Something";
@HttpContext.Current.Session["MyVariable"].ToString()
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx
Upvotes: 0
Reputation: 3202
To save session
@{ HttpContext.Current.Session["Session"] = "Test"; }
To fetch session
@HttpContext.Current.Session["Session"]
Upvotes: 1