Reputation: 819
This may be a stupid question but i can't seem to get a Razor Pages project to locate index files placed in subfolders properly.
Based on this introduction to razor pages: https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-5.0&tabs=visual-studio
The following structure is valid.
File name and path matching URL
/Pages/Index.cshtml / or /Index
/Pages/Contact.cshtml /Contact
/Pages/Store/Contact.cshtml /Store/Contact
/Pages/Store/Index.cshtml /Store or /Store/Index
The last one listed there is what i'm having problems with. It seems that if i try and specify /Store
it will not manage to locate the right page. If i specify /Store/Index
it will work though..
Here's how to replicate this.
Store
Index
_Layout
page to point to asp-page="/Store"
asp-page="/Store/Index"
and run the app to see that the link is properly routed nowAm i completely missing something here?
Upvotes: 1
Views: 2177
Reputation: 30110
The asp-page
attribute requires the name of the page. It is not a URL. Since the page is named Index, you need to include that. The "name" of the page is basically its relative path rooted in Pages, minus the file extension. But the important part to note is that you must include "Index" when trying to link to a file named Index.
Upvotes: 2