剃刀页面生命周期中的ASP.NET MVC [英] Razor page lifecycle in ASP.NET MVC

查看:182
本文介绍了剃刀页面生命周期中的ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一般在问题渲染管线,我已经看到ASP.NET MVC的管道方案,并有一个叫做视图引擎的一步,所以它是如何工作的?我想知道这个情况:


  • 什么是第一次呈现,母版页或查看?

  • 如果我使用到Response.End()在页面开始在 @ {} 块做到这一点interupt页的执行和停止渲染的看法?


解决方案

  

什么是第一次呈现,母版页或查看?


视图。解析器从布局开始,建立了一个LIFO(后进先出)结构递归下降到孩子的意见和谐音。一旦LIFO准备启动弹出和处理的元素。这意味着,最内侧的partials /次将被处理要处理的布局和最后一个之前的布局本身


  

如果我在@使用到Response.End(){}在页面的起始块做到这一点
  页面和止损interupt执行渲染的看法?


在任何视图中使用到Response.End 将导致一个完全空白的页面被渲染。从来没有在任何视图中使用。 到Response.End 基本上是由触发中止当前线程 ThreadAbortException 这是不是您想在剃刀做一些事情意见。

My question in general about render pipeline, i have seen ASP.NET MVC pipeline scheme and there was a step called View Engine, so how it works? I want to know about this scenarios:

  • What is rendered first, master page or view?
  • If i use Response.End() in @{} block at the start of page does this interupt execution of page and stops render of the view?

解决方案

What is rendered first, master page or view?

The view. The parser starts from the Layout and builds a LIFO (Last In First Out) structure recursing down to child views and partials. Once the LIFO is ready it starts popping out and processing the elements. This means that inner-most partials/views will be processed before the layout and the last one to be processed is the Layout itself.

If i use Response.End() in @{} block at the start of page does this interupt execution of page and stops render of the view?

Using Response.End in any view will cause a completely blank page being rendered. Never use in any view. Response.End basically aborts the current thread by triggering a ThreadAbortException which is not something that you want to do in your Razor views.

这篇关于剃刀页面生命周期中的ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆