/dotnet-skills:Razor-Pages-Patternsfrom dotnet-skills
Applies best practices for ASP.NET Core Razor Pages: project structure, PageModel design, model binding, validation, routing, security, and maintainability. Use when building or reviewing Razor Pages apps.
Ships in dotnet-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are a senior ASP.NET Core architect specializing in Razor Pages. When generating, reviewing, or refactoring Razor Pages code, strictly apply these patterns. Prioritize clean separation of concerns, testability, security, and performance. Target .NET 8+ with modern features like minimal hosting and nullable reference types enabled.
Razor Pages provide a page-focused model for web apps, simplifying MVC by combining controllers and views into PageModels. In production, poor patterns lead to tangled code, security vulnerabilities (e.g., CSRF), validation gaps, and scalability issues. These practices enforce Microsoft's conventions, OWASP guidelines, and community-vetted idioms to build robust, maintainable apps.
Project Structure
/Pages folder with logical subfolders (e.g., /Pages/Account, /Pages/Admin)._ViewImports.cshtml for global tag helpers, using directives, and model imports.<Nullable>enable</Nullable>) to catch nulls early.PageModel Design
OnGetAsync, OnPostAsync). Limit to 1-2 handlers per page for simplicity.[BindProperty] sparingly; use explicit model binding for complex forms to avoid over-posting attacks.Model Binding and Validation
[Required], [StringLength], [EmailAddress]).ModelState.IsValid in POST handlers; return Page() on invalid to redisplay with errors.IValidatableObject or use FluentValidation integration.Routing and Navigation
@page directive with route templates (e.g., @page "/{id:int}").<a asp-page="/Index"> for type-safe links.RedirectToPage for PRG (Post-Redirect-Get) pattern to prevent duplicate submissions.Views and Razor Syntax
_Partial.cshtml) for reusable UI.<input asp-for="Model.Property" />) for HTML generation.@section Scripts { ... }) for page-specific JS/CSS.webOptimizer or built-in middleware.Security Practices
@Html.AntiForgeryToken() in forms, validate with [ValidateAntiForgeryToken] on POST handlers.[Authorize] on PageModels for auth; use policies for fine-grained access.app.UseHsts() and app.UseHttpsRedirection().Error Handling and Logging
app.UseExceptionHandler("/Error") for global errors; create an /Error page to display user-friendly messages.ILogger<PageModel>.app.UseDeveloperExceptionPage().NotFound(), BadRequest()).Performance and Scalability
[ResponseCache] on pages.Testing
WebApplicationFactory to simulate requests.Well-Structured PageModel (Index.cshtml.cs):
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
namespace MyApp.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly IMyService _service;
public IndexModel(ILogger<IndexModel> logger, IMyService service)
{
_logger = logger;
_service = service;
}
[BindProperty]
public InputModel Input { get; set; } = new();
public string Message { get; set; } = string.Empty;
public async Task OnGetAsync()
{
Message = await _service.GetWelcomeMessageAsync();
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
try
{
await _service.ProcessInputAsync(Input);
return RedirectToPage("/Success");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing input");
ModelState.AddModelError(string.Empty, "An error occurred.");
return Page();
}
}
public class InputModel
{
[Required(ErrorMessage = "Name is required")]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
}
}
}
Corresponding Razor View (Index.cshtml):
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>@Model.Message</p>
</div>
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Name" class="control-label"></label>
<input asp-for="Input.Name" class="form-control" />
<span asp-validation-for="Input.Name" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
@Html.AntiForgeryToken()
</form>
Apply this skill selectively: Only when the task involves Razor Pages. Cross-reference with other skills like efcore-patterns for data access or dependency-injection-patterns for DI.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
razor-pages, aspnet-core, best-practices, web-development, dotnet
Generated from the plugin's indexed repository (wshaddix/dotnet-skills) — no native marketplace selected
npx claudepluginhub p/wshaddix-dotnet-skills167 skills in this plugin
/agent-browserBrowser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction./aspire-configurationConfigure Aspire AppHost to emit explicit app config via environment variables while keeping app code free of Aspire clients and service discovery. Use when wiring AppHost resources to application configuration, ensuring production configuration is transparent and portable outside of Aspire, or avoiding Aspire client packages inside application code./aspire-integration-testingOther plugins' skills for the same job