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?

1

2 Answers 2

5
@{var sessionvar = Session["myVar"] as FooType;}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.