For example i have web site with heavy layout(masterpage).
And for layout render we need to get some stuff from database and maybe do some calculations.
But where i must put this code?
- Put code in every view(maybe throught render section) is bad idea.
- Layout razor markup ofcourse too. Markup is using for visualization logic but not for business logic.
The Haacked blogged about the Html.RenderAction helper (also refereed as child actions) which seem like a perfect fit for your scenario. It allows you to embed partials/widgets in your site that go through a separate Controller/Model/View lifecycle than the main one. Very useful for incorporating common widgets in your Layout without the need of having your main controller worry about this transverse logic.