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.
Follow the POST, REDIRECT, GET flow from submitted shopping-basket data through validation to a payment page. section 15.4.1
