0

I have created an ASP.NET MVC 5 App.

I try to access to a session variable in the _layout.cshtml view.

The code is the following one :

@{ var user = Session["idUser"];}

The problem is that the error is

Cannot resolve symbol 'Session'

When I define the session variable in my controller it works.

Session["idUser"] = idUser;

Can I access to the Session variable in the view ? If not why ?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
ParkPark
  • 13
  • 5
  • 1
    That looks correct. Sometimes VS gets confused. Try running it. See [here](https://stackoverflow.com/questions/33130521/visual-studio-cannot-resolve-model-but-razor-pages-loads) – Steve Greene Oct 23 '17 at 20:35
  • Yes, it is correct and it works perfectly fine. Thanks. – ParkPark Oct 23 '17 at 20:38

0 Answers0