3

I have the following setup in my project:

/Pages/Page1.razor
/Pages/Page2.cshtml

Page 1 is a Blazor component.

Page 2 is a Razor Page.

At the top of Page1:

@page "/Page1"

In the Page2.cshtml.cs code-behind I have:

public IActionResult OnPostAddNew()
{
    return RedirectToPage("Page1");
}

I have tried everything I can think of but I always get:

InvalidOperationException: No page named 'Page1' matches the supplied values.

I appreciate that Page1 is not technically a page but I haven't been able to figure out how to redirect. A NavLink works just fine to find Page1.

Ed Barnes
  • 41
  • 4
  • Is your project a Blazor one or a Razor Pages App ?You can't mix a Blazor Component Page with a Razor Page the way you do... You can't navigate from a Razor page to a Blazor one by redirection. What are you trying to do ? – enet May 14 '20 at 19:22
  • Basically that. It is a Blazor Server App. I added a Razor Page to it to display a grid component. I want to navigate from that to a .razor page that displays the details. – Ed Barnes May 15 '20 at 15:38
  • Clarification third party grid control not grid component. – Ed Barnes May 15 '20 at 16:00
  • I don't think you can do it. However, you can create a Razor pages app in which you may have a page in which you can embed a Razor component to display data provided to it by the razor page... – enet May 15 '20 at 16:39
  • Yah - the issue I had there was that the bindings were lost. I passed an object to the component and the NotifyProperty changed events stopped firing. The control layout (placement and size) even looked different (component vs. component embedded on a razor page). Hopefully they find a way for the two page types to talk to each other. – Ed Barnes May 15 '20 at 21:18

1 Answers1

3

I was having the same problem redirecting off my Logout page. Just using Redirect instead of RedirectToPage worked for me. RedirectToPage got me the same error as you. In my example the "Counter" page is Counter.razor page in the sample code you get when create a Blazor project in Visual Studio.

public async Task<IActionResult> OnGet()
{
    await _signInManager.SignOutAsync();
    return Redirect("~/Counter");
}

LocalRedirect also appears to work:

return LocalRedirect(Url.Content("~/Counter"));
mhenrickson
  • 496
  • 5
  • 5