Jonathan Wood
Jonathan Wood

Reputation: 67223

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.

Upvotes: 1

Views: 807

Answers (1)

Zhi Lv
Zhi Lv

Reputation: 21421

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.

Upvotes: 1

Related Questions