I wanted to take a default asp.net core MVC project in Visual Studio and then see if I could added Razor pages support and use them both.
I created an MVC project and compared it to a new razor project. Using insight from a stack overflow article "How to extend an ASP.NET Core MVC project by Razor Pages?", I was able to successfully do just that.
The folder structure of the result:
[x] Add a new folder to the project and name it
This is a Razor convention. Other helpful Razor information at the MS Docs site.
[x] Add the line
public void ConfigureServices(IServiceCollection services)
- [x] Add the line
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
At this point, a Razor page can be added and can be navigated to:
- [x] Add a new Razor page results in: basic page code: rendered view:
So now one may wish to use the existing layout options with the new razor pages.
- [x] Copy the
_ViewStart.cshtmlfile from the
>Viewsfolder to the
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
<a class="nav-link text-dark" asp-area="" asp-page="/HelloWorld">Hello Razor</a>
I create this for my own reference and hopefully others will also find it helpful.