ASP.NET Core Razor Pages vs MVC comparison

Posted: (EET/GMT+2)

 

ASP.NET Core gives you two main ways to build HTML-based, server-side rendered web applications: MVC (for Model-View-Controller) and Razor Pages. They share the same underlying features like routing, model binding and filters, but the structure is a bit different.

The MVC model uses controllers and views:

Controllers/
  HomeController.cs
Views/
  Home/
    Index.cshtml

In comparison, Razor Pages puts the code and view together under the Pages folder:

Pages/
  Index.cshtml
  Index.cshtml.cs // a "PageModel", aka "code-behind"

Razor Pages works well when you think in terms of pages or forms: each page has its own handler methods (like OnGet or OnPost) and a model. In contrast, MVC is a good fit when you prefer code-heavier controllers, or when you build larger APIs and want explicit separation.

The nice part is that you can mix them in the same project. You don't have to choose one over the other: you can use Razor Pages for simple UIs, and then MVC controllers for API endpoints or more complex application.