100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C#

Razor Pages Fundamentals

Learn the page-based programming model in ASP.NET Core where markup and code-behind logic live together, simplifying page-focused scenarios without a separate controller layer.

Razor Pages & MVCBeginner9 min readJul 10, 2026
Analogies

What Are Razor Pages?

Razor Pages, introduced in ASP.NET Core 2.0, is a page-focused programming model that pairs a .cshtml view file directly with a code-behind class called a PageModel (in a matching .cshtml.cs file), both living together in the Pages folder by convention. This removes the need to route every page through a separate controller class, which makes simple, page-centric scenarios like login forms, contact forms, or CRUD screens faster to build and easier to navigate because the markup and its logic sit side by side.

🏏

Cricket analogy: It's like how a batter's stance and their shot selection are tightly coupled to the specific ball they face in that over, rather than a separate coach calling every shot from the pavilion the way Virat Kohli reads the bowler's line and reacts on the spot instead of waiting for instructions from the dressing room.

Handler Methods and HTTP Verbs

Each PageModel exposes handler methods named by convention after the HTTP verb they respond to: OnGet or OnGetAsync runs when the page is requested with GET, and OnPost or OnPostAsync runs on form submission via POST. When a single page needs more than one POST action, such as both 'Save' and 'Delete' buttons, named handlers let you disambiguate them using the asp-page-handler tag helper attribute, which the framework maps to methods like OnPostDelete or OnPostDeleteAsync.

🏏

Cricket analogy: This mirrors how an umpire's signal differs by situation: a raised finger means out, arms crossed means no-ball, and a specific wide-ball signal exists too, so the same umpire dispatches to a different 'handler' depending on what happened on the field, just as OnGet and OnPost dispatch by verb.

csharp
// Pages/Products/Edit.cshtml.cs
public class EditModel : PageModel
{
    private readonly ProductContext _context;

    public EditModel(ProductContext context) => _context = context;

    [BindProperty]
    public Product Product { get; set; } = default!;

    public async Task<IActionResult> OnGetAsync(int id)
    {
        Product = await _context.Products.FindAsync(id);
        if (Product is null) return NotFound();
        return Page();
    }

    public async Task<IActionResult> OnPostAsync()
    {
        if (!ModelState.IsValid) return Page();

        _context.Attach(Product).State = EntityState.Modified;
        await _context.SaveChangesAsync();
        return RedirectToPage("./Index");
    }

    public async Task<IActionResult> OnPostDeleteAsync(int id)
    {
        var product = await _context.Products.FindAsync(id);
        if (product is not null)
        {
            _context.Products.Remove(product);
            await _context.SaveChangesAsync();
        }
        return RedirectToPage("./Index");
    }
}

Routing and Model Binding

Razor Pages routing is convention-based on folder structure: a file at Pages/Products/Details.cshtml is served at the URL /Products/Details without any explicit route configuration, and the @page directive at the top of the .cshtml file can add route parameters, for example @page "{id:int}" to accept a numeric id segment. Properties on the PageModel marked with [BindProperty] are automatically populated from posted form data by name-matching convention, and pairing them with DataAnnotations attributes like [Required] or [StringLength] lets ModelState.IsValid drive server-side validation before you touch the database.

🏏

Cricket analogy: This is like how a stadium's gate number directly corresponds to the seating block printed on your ticket — Gate 7 leads to Block C without needing a separate signpost system, just as folder structure maps directly to URL without extra route configuration.

Razor Pages forms rendered with the form tag helper automatically include a hidden antiforgery token input, and the framework validates it on POST without any extra code from you, protecting handlers against cross-site request forgery by default.

When to Choose Razor Pages

Razor Pages shines for page-centric workflows such as forms, wizards, and CRUD screens where each URL corresponds to one clear user task, because the tight PageModel-to-view pairing minimizes ceremony. For applications with heavy API surfaces, complex cross-cutting concerns shared across many unrelated pages, or teams that want a single controller fronting multiple views and content-negotiated responses, the traditional MVC controller/action model (or a hybrid of both, which ASP.NET Core fully supports in the same project) is often a better structural fit.

🏏

Cricket analogy: This is like choosing a specialist opener suited to swinging conditions at Headingley versus an all-rounder like Ravindra Jadeja who handles bowling, batting, and fielding duties across varied situations — pick the tool that matches the specific job.

Do not scatter business logic directly inside .cshtml markup just because Razor Pages colocates view and code — keep the PageModel thin by delegating real logic to injected services, otherwise pages become hard to unit test and the separation of concerns you gained from the code-behind file erodes.

  • Razor Pages pairs a .cshtml view with a PageModel code-behind class, both under the Pages folder.
  • Handler methods like OnGet and OnPost map to HTTP verbs by naming convention.
  • Named handlers (OnPostDelete, invoked via asp-page-handler) let one page support multiple POST actions.
  • Routing is convention-based on folder structure; @page can declare route parameters like "{id:int}".
  • [BindProperty] auto-populates PageModel properties from form posts by name matching.
  • DataAnnotations plus ModelState.IsValid provide server-side validation before persisting data.
  • Razor Pages and MVC controllers can coexist in the same ASP.NET Core project; choose per scenario.

Practice what you learned

Was this page helpful?

Topics covered

#ASPNETCoreStudyNotes#MicrosoftTechnologies#RazorPagesFundamentals#Razor#Pages#Fundamentals#Handler#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse