I am trying to access session data from inside a view.
Use Case: I'm storing status messages in the session that will be displayed at the top of the page. Currently I implemented this by using a DisplayMessages()
function that sets some ViewData[....]
properties and calling it at the beginning of every controller action.
Goal: I want to only set the status message once without needing additional code in the controller to display the messages on the next page load.
So I'm trying to access the messages that are stored in the session directly from the view.
So far I have tried the following:
- Dependency Injection of an IHttpContextAccessor (doesn't seem to work anymore with ASP .NET Core MVC 1.0.0
- Creating a static class to access the session, including the change from
next()
tonext.invoke()
suggested in the comment- This didn't work. I could access the
HttpContext
andSession.IsAvailable
was true, but there was no data in the session.
- This didn't work. I could access the