Search code examples
asp.net-core.net-coreasp.net-core-mvcrazor-pages

Razor Pages and the MVVM Pattern: Exploring the Relationship (MVC or MVVM or ...)


I am confused about the architecture of Razor Pages in ASP.NET Core. Some sources claim that Razor Pages adhere to the MVC pattern, while others argue that they follow the MVVM pattern. Can someone clarify the architecture of Razor Pages and explain whether they should be considered as part of the MVC pattern, MVVM pattern, or something else entirely?

my opinion: I don't believe it follows the MVVM pattern because requests are made inside the page model (the ViewModel of MVVM) rather than inside the view. Therefore, it does not adhere to MVVM principles.

It appears to be an MVC structure with the C and M components within the page model.

enter image description here

some related links

With regards to razor, what is difference between .NET MVC support for razor vs .NET razor pages and is there anything called .NET MVC razor pages?

WPF MVVM vs Razor Page MVVM


Solution

  • It appears to be an MVC structure with the C and M components within the page model.

    This is how I see Razor Pages, as I mentioned in one of the accepted answers you linked to. Each page has its own controller, implemented as a PageModel class, which represents an example of the Page Controller pattern. It is responsible for processing input from the request and preparing a model for the view (the .cshtml file). The only real difference between MVC and Razor Pages is that an MVC controller is typically scoped to an entity rather than a single page, although there is nothing to stop you scoping an MVC controller to an endpoint.

    enter image description here