Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor page lifecycle in ASP.NET MVC

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?
like image 581
Alexander Avatar asked Nov 19 '11 13:11

Alexander


People also ask

Can you use Razor pages with MVC?

You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.

What is the page life cycle in ASP.NET MVC?

The life cycle is basically is set of certain stages which occur at a certain time. MVC actually defined in two life cycles, the application life cycle, and the request life cycle. The Starting point for every MVC application begins with routing.

What is difference between MVC and Razor pages?

A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.

What is ASP.NET MVC Razor?

Razor is one of the view engines supported in ASP.NET MVC. Razor allows you to write a mix of HTML and server-side code using C# or Visual Basic. Razor view with visual basic syntax has . vbhtml file extension and C# syntax has .


2 Answers

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.

like image 104
Darin Dimitrov Avatar answered Sep 23 '22 00:09

Darin Dimitrov


Have a look at Steve Sanderson's Request-Handling Pipeline Poster. It explains the whole request process quite in detail. It's from MVC version 1.0, but it's still valid. Just replace 'WebForm' with Razor.

It really shouldn't bother you whether the master or the view is rendered first. Could you explain why this matters to you?

like image 30
kay.herzam Avatar answered Sep 20 '22 00:09

kay.herzam