15 Generating responses with page handlers in Razor Pages

 

This chapter covers

  • Selecting which page handler in a Razor Page to invoke for a request
  • Returning an IActionResult from a page handler
  • Handling status code errors with StatusCodePagesMiddleware

In chapter 14 you learned how the routing system selects a Razor Page to execute based on its associated route template and the request URL, but each Razor Page can have multiple page handlers. In this chapter you’ll learn all about page handlers, their responsibilities, and how a single Razor Page selects which handler to execute for a request.

In section 15.3 we look at some of the ways of retrieving values from an HTTP request in a page handler. Much like minimal APIs, page handlers can accept method arguments that are bound to values in the HTTP request, but Razor Pages can also bind the request to properties on the PageModel.

In section 15.4 you’ll learn how to return IActionResult objects from page handlers. Then you look at some of the common IActionResult types that you’ll return from page handlers for generating HTML and redirect responses.

15.1 Razor Pages and page handlers

15.2 Selecting a page handler to invoke

15.3 Accepting parameters to page handlers

15.4 Returning IActionResult responses

15.4.1 PageResult and RedirectToPageResult

15.4.2 NotFoundResult and StatusCodeResult

15.5 Handler status codes with StatusCodePagesMiddleware

Summary

sitemap