Suraj K Mad
Suraj K Mad

Reputation: 285

session in MVC-3(Razor-View Engine)

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

Answers (2)

Kinexus
Kinexus

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

To save session

@{ HttpContext.Current.Session["Session"] = "Test"; }

To fetch session

@HttpContext.Current.Session["Session"]

Upvotes: 1

Related Questions