Razor Pages is a page-based programming model in ASP.NET Core, designed to simplify building web applications. Unlike MVC, where logic is split into controllers and views, Razor Pages keeps page-specific logic and UI together, making it easier for beginners to manage and maintain.
Key Features:
- Simplified structure for page-centric apps
- Supports server-side processing and dynamic content
- Uses .cshtml files combining HTML and C#
- Integrated with routing and model binding
- Supports dependency injection and validation
Example:
A simple Razor Page to display “Hello World”:
@page
@model IndexModel
<h1>Hello World!</h1>
@code {
public string Message { get; set; } = "Welcome to Razor Pages!";
}
Razor Pages is ideal for small to medium web apps or when you want clean separation of pages without the overhead of full MVC.
Citations: