ASP.NET MVC 3, Razor Layout Controller-like?

Did not find anything about how to do this. I require some code to run to update the data in a Razor layout.

I could do this by running the code in each Action that uses the layout and sets the ViewBag data, but this seems impossible ...

So how would I do it better?

+4
source share
2 answers

The answer to this question suggests using a global action filter .

This is the part of the code (filter) that is executed for each action, you can use it to set properties in the ViewBag. These properties are available from each view and from the layout.

+3
source

If the data that you visualize in your layout is orthogonal to the data of your actual view (what it should be, or else you use layouts where you should use partial views), then imho is conceptually the most robust method to use a child action (i.e. using Html. Action) to display the data in the layout.

+2
source

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


All Articles