Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement logic at "masterpage" level

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.

like image 915
Steffen Avatar asked Mar 08 '11 16:03

Steffen


2 Answers

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.

like image 75
SLaks Avatar answered Nov 02 '22 22:11

SLaks


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).

like image 22
Jakub Konecki Avatar answered Nov 02 '22 22:11

Jakub Konecki