I'm still new to MVC, so bear with me :-)
I've got a community site I'm working on, and I'd like to show how many users are online on all my pages after the user's been logged in.
I've got a shared view which is used as layout for all pages after login (UserLayout.cshtml)
Can I somehow add the logic to show online count to my shared layout ?
If it were WebForms I'd just have some code-behind for my masterpage, but this is obviously not an option here.
The information about users online is fetched from a cache. It's not available as a property on any of my View Models.
You can write an action which renders the information (using a very small view)
You can then call Html.Action
to render it from the layout page.
You can create a 'UserLayoutModel' class and have all other view models derive from it. You can also use 'RenderAction' to have a part of the UI rendered separately (make sure you mark this action with ChildActionOnly attribute).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With