What is the execution order of an MVC Razor view/layout

后端 未结 4 1880
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 21:16

I have a razor layout like:

@using (var context = SetUpSomeContext()) {
    
Some content here @RenderBody();
} <
4条回答
  •  执笔经年
    2021-01-03 22:12

    The execution order is from innermost to outermost.

    I would argue that using a 'context' the way you use it is not the best design - you should consider moving the setup to the controller / action filter and pass the data to the views in model.

提交回复
热议问题