Can we Get those Values which is in Session directly in asp.net MVC Views?
I have tried it in Controller it Works,I can easily get & set the Value,
But how to Get value directly from Session in Views?
Can we Get those Values which is in Session directly in asp.net MVC Views?
I have tried it in Controller it Works,I can easily get & set the Value,
But how to Get value directly from Session in Views?
You can, but you shouldn't as this is considered as bad practice. Views are not supposed to pull data. They should use data passed 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 by using the Session property of the View page:
<%= this.Session["someKey"] %>