Search code examples
c#asp.net-corerazor-pages

Error redirecting to page under Areas section


I have an Index.cshtml Razor Page under my Areas section.

enter image description here

And I'm trying to redirect to that page with the following code.

return RedirectToPage("/Index", new { area = BusinessType.Storage });

But this produces an error.

An unhandled exception occurred while processing the request.

InvalidOperationException: No page named '/Index' matches the supplied values.

Microsoft.AspNetCore.Mvc.Infrastructure.RedirectToPageResultExecutor.ExecuteAsync(ActionContext context, RedirectToPageResult result)

I don't quite understand this error, or why my redirect isn't working.


Solution

  • The area value needs to be a string. Try to use the following code, instead:

    return RedirectToPage("/Index", new { area = "Storage" });
    

    You can set a breakpoint to check the value and type of BusinessType.Storage, since the error calls out that property.