Razorpages wont redirect after POST
VictorioBerra opened this issue · comments
My razorpages code is as follows:
[BindProperty]
public CreateTeamViewModel CreateTeamRequest { get; set; } = default!;
public async Task<IActionResult> OnPostAsync(CancellationToken cancellationToken)
{
var result = await this.validator.ValidateAsync(this.CreateTeamRequest!, cancellationToken);
if (!result.IsValid)
{
result.AddToModelState(this.ModelState);
return this.Page();
}
var newTeam = new Team
{
// .....
};
this.context.Teams.Add(newTeam);
await this.context.SaveChangesAsync(cancellationToken);
return this.RedirectToPage("/Teams/Invite", new { teamId = newTeam.Id });
}
Chrome sees the 302:
My page never navigates:
Looks like Form Helper takes over the post, and instead makes it an AJAX call? Shouldn't it respect a 302?
So I see I should have used:
return FormResult.CreateSuccessResult(
"Product saved. Please wait...",
this.Url.Page("/Teams/Invite", new { teamId = newTeam.Id }));
that works. But the README says:
You can also use the form validator without ajax.
How do I do that?