liveBook · Manning

Chapter 15: Generating responses with page handlers in Razor Pages

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

This chapter introduces how Razor Pages select and run page handlers, bind request data, return results, and improve error responses.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces how Razor Pages select and run page handlers, bind request data, return results, and improve error responses.

Key terms: Razor Page, page handler, routing, route template, method arguments, PageModel, binding, IActionResult, PageResult, RedirectToPageResult

15.1 Razor Pages and page handlers

This section defines Razor Page handlers as the PageModel entry point for requests, responsible for coordinating validation, application work, and response selection without rendering or implementing business logic themselves.

Key terms: page handler, PageModel, application model, PageResult, RedirectToPageResult, void, Task, Razor view, view engine, MVC design pattern

15.2 Selecting a page handler to invoke

This section explains how EndpointMiddleware chooses one Razor Page handler from the request’s HTTP verb and optional handler route value, including its fallback behavior.

Key terms: EndpointMiddleware, page handler, HTTP verb, handler route value, RoutingMiddleware, OnGet, OnPostAsync, OnPostCustomSearch, Async suffix, query string

15.3 Accepting parameters to page handlers

This section explains how Razor Pages page handlers receive model-bound request values, validate them, and choose suitable response return types.

Key terms: model binding, Razor Pages, simple types, complex types, page handler, method arguments, PageModel, [BindProperty], SupportsGet, ModelState

15.4 Returning IActionResult responses

This section introduces IActionResult as the Razor Pages mechanism that represents a handler’s chosen response and explains why it separates response decisions from response generation.

Key terms: IActionResult, page handler, Razor Pages infrastructure, view engine, MVC design pattern, action method logic, IResult, PageResult, ViewResult, PartialViewResult

15.4.1 PageResult and RedirectToPageResult

This section explains when Razor Page handlers return HTML with PageResult or move the browser to another page with RedirectToPageResult, including the stateless nature of multi-page flows.

Key terms: PageResult, Razor view, HTML response, RedirectToPageResult, HTTP redirect, POST, REDIRECT, GET, stateless, TempData, cookies, database

15.4.2 NotFoundResult and StatusCodeResult

This section shows how Razor Pages handlers return raw 404 and other HTTP status-code responses, and why those responses usually need user-friendly handling in web pages.

Key terms: NotFoundResult, StatusCodeResult, HTTP status code, 404, middleware pipeline, raw 404 status code, HTML, Razor Pages, API, StatusCodePagesMiddleware

15.5 Handler status codes with StatusCodePagesMiddleware

This section explains how StatusCodePagesMiddleware turns empty 4xx and 5xx Razor Pages responses into friendlier error pages, especially by reexecuting the pipeline or redirecting.

Key terms: StatusCodePagesMiddleware, UseStatusCodePages, 4xx, 5xx, response body, middleware pipeline, UseStatusCodePagesWithReExecute, reexecute, error handling path, format string token

15.6 Summary

This summary recaps how Razor Page handlers process requests, bind input, choose response results, and handle error status codes.

Where this is used later

Concepts explained in this chapter

← Chapter 14: Mapping URLs to Razor Pages using routing Chapter 16: Binding and validating requests with Razor Pages →

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.