liveBook · Manning

PageResult

As explained in ASP.NET Core in Action, 3e

PageResult is an ASP.NET Core action result that renders the associated Razor Page as HTML and returns a successful response.

PageResult tells Razor Pages to render the associated Razor view as HTML and return a successful 200 response. The page handler selects this result; the view engine generates the response. section 15.1 section 15.4

Use PageResult when a handler should return the current page rather than redirect elsewhere:

  • Return Page() from the PageModel; this helper creates a PageResult. section 15.6
  • Returning void has the same rendering effect for a handler, because the associated Razor view is rendered implicitly. section 15.1 section 15.3
  • Choose RedirectToPageResult instead when the browser should move to another Razor Page, such as after form submission. section 15.4.1

Returning the current Razor Page

After validating bound input and calling application logic, a page handler can finish with `return Page();`. Razor Pages then renders the associated view. A search handler can set its results and return the search page; a POST handler may instead redirect when the workflow moves to another page. section 15.3 section 15.4.1

Figure 15.3 A typical POST, REDIRECT, GET flow through a website. A user sends their shopping basket to a checkout page, which validates its contents and redirects to a payment page without the user’s having to change the URL manually.
CH15_F03_Lock3

Follow the POST-REDIRECT-GET flow to see why a handler returns PageResult when displaying the current page and RedirectToPageResult when continuing to another page. section 15.4.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains result selection, view rendering, status code, and Page() creation while deferring rendering internals to later treatment.
Examples
Uses Page(), new PageResult(), a search handler, and a checkout POST-REDIRECT-GET flow.
What it assumes
Assumes Razor Pages and page handlers while introducing result selection, view rendering, and the Page() helper.
What you can do after
Apply it via PageModel.Page() to return rendered HTML from a Razor Page handler.
How it connects
Connects PageResult with Razor Pages, page handlers, IActionResult, Razor views, model binding, and POST-REDIRECT-GET.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.