Exploring ASP.NET Core Razor Pages
Explore how to build dynamic web pages using ASP.NET Core Razor Pages by blending C# code with HTML markup. Learn to convert static pages to Razor Pages, enable necessary services, and manage page lifecycle methods to handle HTTP requests. Understand the use of Razor syntax, directives, and how to output dynamic data like the current day on your website.
We'll cover the following...
ASP.NET Core Razor Pages allow developers to easily mix C# code statements with HTML markup to make the generated web page dynamic. That is why Razor Pages uses the .cshtml file extension. By convention, ASP.NET Core looks for Razor Pages in a folder named Pages.
Enabling Razor Pages
We will now copy and change the static HTML page into a dynamic Razor Page and then add and enable the Razor Pages service:
Step 1: In the Northwind.Web project folder, create a folder named Pages.
Step 2: Copy the index.html file into the Pages folder (in Visual Studio, hold down Ctrl while dragging and dropping.)
Step 3: For the file in the Pages folder, rename the file extension from .html to .cshtml.
Step 4: In ...