pongahead
pongahead

Reputation: 2024

access session variable from layout page ASP.NET MVC3 RAZOR

I want to access a session variable from my layout master page, but you cant have a model in a layout page, so how do I access this variable?

Upvotes: 1

Views: 7247

Answers (2)

SLaks
SLaks

Reputation: 888303

You should move that logic to a child action and call the child action from the master page using @Html.Action(...).

To answer the question, use the Session property.

Upvotes: 1

Alex
Alex

Reputation: 35417

@{var sessionvar = Session["myVar"] as FooType;}

Upvotes: 5

Related Questions