简体   繁体   中英

Where is best place for asp.net mvc layouts logic

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?

  1. Put code in every view(maybe throught render section) is bad idea.
  2. 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.

您应该将该逻辑放在子操作中并在布局中调用它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM