Have you tested ASP.NET Razor Pages yet?

Posted: (EET/GMT+2)

 

If you haven't tested Razor Pages yet, now is a great time to take a look. Razor Pages was introduced in ASP.NET Core 2.0, and by now the ecosystem is mature enough that you can confidently use Razor Pages in production.

The idea is simple: instead of the classic MVC pattern with controllers and actions, you place your view and its handler logic together in a single folder structure. This makes many page-based scenarios—forms, CRUD operations, simple dashboards—much easier to write (and understand).

A Razor Page consists of:

  • A .cshtml file for markup
  • A companion .cshtml.cs "page model" file for handlers like OnGet() and OnPost()

In practice, this means you avoid a lot of boilerplate code for controllers and actions. You just create a folder, drop in a page, and start writing. Visual Studio 2017 and 2019 both come with excellent scaffolding support, too.

If your application is very page-driven, Razor Pages can make your codebase feel more natural and compact. I recommend that you give them a try; especially if you already enjoy using MVC with Tag Helpers.