Skip to content
Learn Netverks

Lesson

Step 20/36 56% through track

razor-pages-intro

Razor Pages intro

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

An orientation to the ASP.NET track—how the server playground works, core vocabulary, and what you will practice next.

You need a clear map of the ASP.NET track so middleware, dependency injection, and the .NET project layout do not feel like magic.

You will apply Razor Pages intro in contexts like: Internal portals, admin dashboards, and hybrid SSR + SPA shells.

Write C# (top-level or Program class), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After HTML fundamentals and basic programming concepts—before or alongside SQL.

Razor Pages combine a page-focused alternative to MVC—each .cshtml file pairs with a PageModel class. Ideal for form-heavy sites without deep controller hierarchies.

File structure

Pages/
  Index.cshtml
  Index.cshtml.cs   // PageModel
  Shared/
    _Layout.cshtml

PageModel handlers

public class IndexModel : PageModel {
    public void OnGet() { }
    public IActionResult OnPost() {
        if (!ModelState.IsValid) return Page();
        return RedirectToPage("/Success");
    }
}

Convention: OnGet, OnPost, OnPostAsync map to HTTP verbs.

MVC vs Razor Pages

MVC groups by controller; Razor Pages group by page. Both use Razor syntax and share DI, auth, and EF Core—pick based on team preference and app shape.

Important interview questions and answers

  1. Q: Can you mix MVC and Razor Pages?
    A: Yes in one project—route carefully to avoid conflicts.
  2. Q: When prefer Razor Pages?
    A: Page-centric apps, tutorials, internal tools with many similar forms.

Self-check

  1. Which method handles GET on a Razor Page?
  2. Where does shared layout live?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • PageModel vs controller?
  • Layout page?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump