Programmer's Picnic · Learn With Champak
Razor course · Lesson 1 of 4

Create a Razor Pages project

Read the explanation, run the sample, and try the exercise.

Install and create

Install the supported .NET SDK, then:

dotnet new webapp -n PicnicRazor
cd PicnicRazor
dotnet run

Open the exact local URL printed by your terminal.

Explore files

Pages/Index.cshtml contains markup and Razor. Pages/Index.cshtml.cs contains the C# PageModel. Shared/_Layout.cshtml is a common layout; wwwroot contains static files.

Edit Index.cshtml

@page
@model IndexModel
<h1>My first Razor website</h1>
<p>Today is @DateTime.Now.ToString("dddd")</p>

Keep the matching generated Index.cshtml.cs file. Refresh after saving.

← PreviousNext lesson →