# Razor Pages Patterns

The Razor Pages Patterns skill gives the agent a fixed set of rules for ASP.NET Core Razor Pages: page layout, PageModel design, binding and validation, form security. Fits projects on .NET 8+ with Razor Pages as the UI.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 121 installs · ★ 92 repo stars
- Author: wshaddix
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/razor-pages-patterns/SKILL.md
- Updated: 2026-02-27
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/razor-pages-patterns

## What it does

The skill steers the agent toward a page-first layout whenever it writes or reviews Razor Pages code. Pages sit under `Pages` in topical subfolders, services arrive through the PageModel constructor, and handlers stay short and async. `[BindProperty]` gets used sparingly so a POST cannot set fields it should not touch.

Validation runs on data annotations plus a `ModelState.IsValid` check that sends the user back to the form with errors. Routing uses `@page` templates and `RedirectToPage` after a successful submission. Security means CSRF tokens in every form, `[Authorize]` on PageModels, HSTS with HTTPS redirection. Separate parts cover logging through `ILogger<PageModel>` and a shared `/Error` page, response caching and PageModel unit tests with mocks.

Everything assumes .NET 8+ with nullable reference types switched on. On an older target the advice about minimal hosting and null-safe code will not match your startup.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill razor-pages-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/razor-pages-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/razor-pages-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill razor-pages-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/razor-pages-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill razor-pages-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/razor-pages-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install wshaddix/dotnet-skills skills/razor-pages-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/razor-pages-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill razor-pages-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/wshaddix/dotnet-skills --path skills/razor-pages-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/razor-pages-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill razor-pages-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/razor-pages-patterns/SKILL.md

## When to use it
- lay out pages under `Pages` without mixing them with API controllers
- drop stray `[BindProperty]` uses that allow over-posting
- wire a CSRF token and `[Authorize]` into a page
- make handlers async and inject services through the constructor
- unit test a PageModel with mocked dependencies

## Example prompts
- Create a PageModel for the signup form at `Pages/Account/Register.cshtml.cs` with validation and a CSRF token.
- Review `Pages/Admin/Index.cshtml` for over-posting and add `[Authorize]`.
- Rework `OnPostAsync` to follow Post-Redirect-Get with `RedirectToPage`.

## Similar
- [csharp-razorpages](https://affpapa.org/en/nevibecode/rules/csharp-razorpages.md) — rule · ★ 41430 repo stars
- [dependency-injection-patterns](https://affpapa.org/en/nevibecode/skills/dependency-injection-patterns.md) — skill · 715 installs
- [create-datadriven-aspnetcore](https://affpapa.org/en/nevibecode/skills/create-datadriven-aspnetcore.md) — skill · 3900 installs
- [aspnet-core](https://affpapa.org/en/nevibecode/skills/aspnet-core.md) — skill · 4300 installs
- [dotnet-architect](https://affpapa.org/en/nevibecode/skills/dotnet-architect.md) — skill · 353 installs
- [csharp](https://affpapa.org/en/nevibecode/rules/csharp.md) — rule · ★ 41430 repo stars

From the same set: [wshaddix/dotnet-skills](https://affpapa.org/en/nevibecode/by/wshaddix/dotnet-skills.md) — 24 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
