1

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
pongahead
  • 1,984
  • 3
  • 18
  • 21
  • Possible duplicate of [Accessing a Session object from Razor \_Layout.cshml](http://stackoverflow.com/questions/4381189/accessing-a-session-object-from-razor-layout-cshml) – Liam Apr 27 '17 at 12:47

2 Answers2

5
@{var sessionvar = Session["myVar"] as FooType;}
Alex
  • 34,899
  • 5
  • 77
  • 90
1

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964