liveBook · Manning

Chapter 13: Creating a website with Razor Pages

What you will learn in chapter 13 of ASP.NET Core in Action, 3e

This chapter introduces Razor Pages as ASP.NET Core’s approach for building server-rendered HTML applications and previews how it uses the MVC design pattern.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces Razor Pages as ASP.NET Core’s approach for building server-rendered HTML applications and previews how it uses the MVC design pattern.

Key terms: API, JSON, XML, HTML web application, Razor Pages, server-rendered HTML, server-rendered, page-based applications, HTML, URLs

13.1 Your first Razor Pages application

This section introduces creating a Razor Pages application from the default template and previews how its middleware, HTML generation, and page handlers compare with minimal APIs.

Key terms: Razor Pages, template, minimal API application, middleware, HTML, page handlers, endpoint handlers

13.1.1 Using the Web Application template

This section shows how to create, run, and inspect the starter Razor Pages application produced by the ASP.NET Core Web App template.

Key terms: ASP.NET Core Web App, Razor Pages, Web Application template, Configure for HTTPS, Enable Docker, top-level statements, F5, dotnet run, Welcome page, Home

13.1.2 Adding and configuring services

This section configures a Razor Pages application in Program.cs by registering Razor Pages, arranging middleware, mapping Razor Page endpoints, and starting the app.

Key terms: WebApplicationBuilder, WebApplication, Build(), Run(), Program.cs, ExceptionHandlerMiddleware, HstsMiddleware, HttpsRedirectionMiddleware, StaticFileMiddleware, RoutingMiddleware

13.1.3 Generating HTML with Razor Pages

This section explains how Razor Pages are found for requests and how .cshtml templates combine Razor directives, C#, HTML, layouts, and PageModels to generate a web response.

Key terms: Razor Pages, Pages folder, routing middleware, endpoint middleware, .cshtml, Razor, @page, @model, PageModel, ViewData

13.1.4 Handling request logic with page models and handlers

This section explains how Razor Page page models and convention-based handlers run request logic separately from Razor templates, illustrated by a GET request to the Privacy page.

Key terms: page model, PageModel, page handler, code-behind file, Razor Page, OnGet, GET request, void, IActionResult, Razor template

13.2 Exploring a typical Razor Page

This section examines a typical Razor Page whose handler binds request input, uses an injected service to load data, and supplies that data to a Razor view for HTML rendering.

Key terms: PageModel, page handler, OnGet, model binding, ToDoService, dependency injection, Page(), Razor view, void, MVC

13.3 Understanding the MVC design pattern

This section explains MVC as a separation of application data and business logic from UI rendering, and maps its roles and request flow to Razor Pages.

Key terms: MVC, model, view, controller, PageModel, page handler, HTTP request, injected services, application model, view model

13.4 Applying the MVC design pattern to Razor Pages

This section positions Razor Pages as an MVC-based framework built on ASP.NET Core MVC and introduces how routed requests reach page handlers to produce HTML.

Key terms: Razor Pages, ASP.NET Core MVC, MVC design pattern, controllers, action methods, page handlers, MVVM, Model-View-View Model, PageModel, two-way data binding

13.4.1 Directing a request to a Razor Page and building a binding model

This section traces how a Razor Pages request is routed to a page endpoint and turned into bound request data before its handler runs.

Key terms: routing middleware, route patterns, route template, Razor Page endpoint, page handler, binding model, binding, PageModel, query string, category

13.4.2 Executing a handler using the application model

This section explains how a Razor Pages handler acts as the MVC controller by validating a request, calling the application model, and choosing a response.

Key terms: page handler, controller, MVC pattern, binding model, application model, domain model, services, database interaction, infrastructure

13.4.3 Building HTML using the view model

This section explains how a Razor Pages PageModel supplies view-model data to a Razor view, which independently renders the final HTML response.

Key terms: view model, application model, PageModel, Razor view, page handler, HTML response, middleware pipeline

13.4.4 Putting it all together: A complete Razor Page request

This section combines the Razor Pages request-to-response flow and explains why its MVC separation of concerns reduces tight coupling.

Key terms: Razor Pages, MVC pattern, page handler, controller, application model, view, separation of concerns, tight coupling, page handler methods, IActionResult

13.5 Summary

This summary recaps how Razor Pages are discovered and handled, how Razor renders dynamic HTML, and how separation of concerns structures a Razor Pages application.

Where this is used later

Concepts explained in this chapter

← Chapter 12: Saving data with Entity Framework Core Chapter 14: Mapping URLs to Razor Pages using routing →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.