I am working with ASP.net 5.0(deprecated I know) so I want to add a webpage(razor page (.cshtml)) and link it to the nav bar as an nav item…. In HTML its just so simple use anchor tag and link it but no its not working in asp.net, so anybody here can provide details or documentation for doing this, I am a beginner so please any help would be appreciated
2
Answers
E.g You have this in your layouts page
You will need a controller named Home for that webpage all you need to do is create a method in the Home controller that routes to that page
Note the should be located razor page should be in Home folder(The name of your controller) located in Views folder
Create a folder named Pages and place your Razor page in that. Ensure that you have added the Razor Pages services and endpoints in Startup:
(https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-5.0&tabs=visual-studio)
In the anchor tag helper, make sure you use the
asp-page
attribute and pass in the relative path of your page rooted in the Pages directory, without the file extension. It should look like this: