Exploring Razor Pages
Razor Pages allow a developer to easily mix HTML markup with C# code statements. That is why they use the .cshtml
file extension.
By default, ASP.NET Core looks for Razor Pages in a folder named Pages
.
Enabling Razor Pages
You will now change the static HTML page into a dynamic Razor Page, and then add and enable the Razor Pages service.
- In the
NorthwindWeb
project, create a folder namedPages
. - Move the
index.html
file into thePages
folder. - Rename the file extension from
.html
to.cshtml
. - In
Startup.cs
, in theConfigureServices
method, add statements to add Razor Pages and its related services like model binding, authorization, antiforgery, views, and tag helpers, as shown highlighted in the following code:public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); }
- In
Startup.cs
, in theConfigure
method, in the configuration to use endpoints, add a statement to useMapRazorPages
, as shown...