Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Razorpages wont redirect after POST #37

Open
VictorioBerra opened this issue Feb 9, 2023 · 2 comments
Open

Razorpages wont redirect after POST #37

VictorioBerra opened this issue Feb 9, 2023 · 2 comments

Comments

@VictorioBerra
Copy link

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:

image

My page never navigates:

image

Looks like Form Helper takes over the post, and instead makes it an AJAX call? Shouldn't it respect a 302?

@VictorioBerra
Copy link
Author

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?

@VictorioBerra
Copy link
Author

Okay after digging through samples, I found that I need [FormValidator] attribute. Turns out that it doesn't work for RazorPages:

image

What do I do now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant