Exploring ASP.NET Core Razor Pages
ASP.NET Core Razor Pages allow a developer to easily mix C# code statements with HTML markup to make the generated web page dynamic. That is why Razor Pages use the .cshtml
file extension.
By convention, ASP.NET Core looks for Razor Pages in a folder named Pages
.
Enabling Razor Pages
You will now copy and change the static HTML page into a dynamic Razor Page, and then add and enable the Razor Pages service:
- In the
Northwind.Web
project folder, create a folder namedPages
. - Copy the
index.html
file into thePages
folder (in Visual Studio, hold down Ctrl while dragging and dropping.) - For the file in the
Pages
folder, rename the file extension from.html
to.cshtml
. - In
index.cshtml
, remove the<h2>
element that says that this is a static HTML page. - In
Program.cs
, before the statement that builds theapp
, add a statement to add ASP.NET Core Razor Pages and its related services, such as model binding...