liveBook · Manning

RedirectToPageResult

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

RedirectToPageResult is an ASP.NET Core Razor Pages result that instructs the client to navigate to a different page.

RedirectToPageResult is a Razor Pages response result that tells the browser to navigate to another Razor Page. A page handler selects this result; the framework then sends the redirect response. section 15.1 section 15.4.1

Use RedirectToPageResult when:

  • Returning a redirect instead of rendering the current page’s HTML. section 15.4.1
  • Completing a successful form POST and sending the browser to a follow-up GET page. section 16.3.2
  • Creating the result conveniently with the PageModel RedirectToPage() helper. section 15.6 section 15.3

Redirect after a successful checkout

public IActionResult OnPost() { if (!ModelState.IsValid) { return Page(); } // Save to the database, update the user, and return success return RedirectToPage("Success"); } Invalid input redisplays the form with validation errors. Successful input redirects to Success.cshtml, so refreshing the final page does not repeat the POST. section 16.3.2

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 from submitted shopping-basket data through validation to a payment page. section 15.4.1

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

How deep it goes
Explains the result choice, helper method, 302 response, and POST-REDIRECT-GET rationale without covering redirect implementation internals.
Examples
Uses checkout validation, Success.cshtml, shopping-basket navigation, and payment-page redirection as concrete examples.
What it assumes
Assumes Razor Pages page handlers and distinguishes redirect results from PageResult HTML rendering.
What you can do after
Apply it via the RedirectToPage() helper to send users from a successful handler operation to another Razor Page.
How it connects
Connects Razor Pages, page handlers, PageResult, IActionResult, ModelState, 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.