Home > Net >  With regards to razor, what is difference between .NET MVC support for razor vs .NET razor pages and
With regards to razor, what is difference between .NET MVC support for razor vs .NET razor pages and

Time:11-23

.NET presently has 5 ways to build web sites that produce the content via trip to the server:

  • .NET framework 4.8 - MVC (ignore this for the purpose of this question)
  • .NET framework 4.8 - Web forms (ignore this for the purpose of this question)
  • .NET MVC with support for razor
  • .NET Razor pages
  • Blazor (ignore this for the purpose of this question)

Question 1: I am trying to understand - with regards to the concept of razor, what is the difference between .NET MVC support for razor vs .NET razor pages? I will attempt to give my understanding below:

  • I know that point 1 is MVC. Point 2 is MVVM.

  • I know that - .NET MVC support for razor are MVC (model, view, controller concept) with support for razor syntax on the view pages, without any code-behind (I mean that the logic is at the controller level). Whereas .NET razor pages are the MVVM approach like the page (razor syntax) and code behind.

Is this correct?

Question 2: I heard my colleague talk about .NET MVC razor pages. I am confused because I have never come across such a thing. My understanding is that .NET MVC is different to .NET Razor pages. Is there anything called .NET MVC razor pages?

Question 3: This article (https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/modern-web-applications-characteristics#traditional-and-spa-behaviors-supported) mentions:

ASP.NET Core supports both MVC (Views or Page based)

How can MVC be page based when the name (MVC) itself says it is view based? Can someone give me clarity on this?

CodePudding user response:

Razor is a templating syntax. It enables C# to be embedded in HTML so that you can use C# to generate part of the HTML dynamically at runtime.

MVC is a server-side development framework that encourages you to use the Model-View-Controller architecture for building your web applications. It uses Razor for its default View engine.

Razor Pages is an alternative server-side development framework, which relies on a page-centric approach to web application development. It uses Razor as its templating syntax.

MVVM is a design pattern that is used in applications that run on the client - for example, WPF, Xamarin and some Javascript-based SPA frameworks. I've seen it used to describe Razor Pages, but I don't agree, and feel that calling Razor Pages MVVM just causes confusion.

ASP.NET Core MVC encourages a "front Controller" approach, in that a single controller can be responsible for processing multiple routes, whose only connection is that they relate to the same entity. Razor Pages can also be seen as an implementation of MVC that uses a Page Controller approach instead. The PageModel class is analogous to a controller for the page.

  • Related