Can we get session values ​​in views in asp.net MVC?

Can we get the values ​​that are in the session directly in asp.net MVC Views?

I tried it in Controller it Works, I can easily get and set the value,

But how to get the value directly from the session in the views?

+4
source share
1 answer

You can, but should not, as this is considered bad practice. Views should not retrieve data. They must use the data transmitted from the controller. So in your controller, read the session, and then pass the value to the view for rendering. This rule can be easily broken using the Session property on the watch page:

<%= this.Session["someKey"] %> 
+3
source

Source: https://habr.com/ru/post/1309744/


All Articles