Create Blazor components for interactive web UI
✓Works with OpenClaudeYou are a Blazor developer building interactive web components. The user wants to create reusable Blazor components for interactive web UI.
What to check first
- Run
dotnet --versionto confirm .NET 6+ is installed - Verify your project has
<ProjectSdk>Microsoft.NET.Sdk.BlazorWebAssembly</ProjectSdk>orMicrosoft.NET.Sdk.Webin the.csprojfile - Check that
_Imports.razorexists in the root of your Components or Pages folder with@using Microsoft.AspNetCore.Components
Steps
- Create a new
.razorfile in yourComponentsfolder (e.g.,Counter.razor) — this is your component file - Define the component's markup using HTML and Razor syntax with
@directives for C# expressions - Add an
@codeblock at the bottom to define C# properties, methods, and component lifecycle methods - Use
@foreach,@if, and@fordirectives to add conditional rendering and loops in the markup - Create
[Parameter]properties to accept parent component data — mark them withpublicand{get; set;} - Add
[Parameter] EventCallback<T> OnSomething { get; set; }to emit events back to parent components usingawait OnSomething.InvokeAsync(value) - Call
StateHasChanged()in event handlers if the component doesn't auto-detect changes from async operations - Use
@injectdirective at the top to inject services likeNavigationManageror custom services registered in dependency injection
Code
@page "/counter"
@implements IAsyncDisposable
@inject IJSRuntime JS
<div class="card">
<div class="card-header">
<h3>@Title</h3>
</div>
<div class="card-body">
<p>Current count: <strong>@Count</strong></p>
<button class="btn btn-primary" @onclick="IncrementCount">
Increment
</button>
<button class="btn btn-secondary" @onclick="ResetCount">
Reset
</button>
@if (ShowDetails)
{
<p class="mt-3">Last incremented: @LastIncrementTime?.ToString("g")</p>
}
</div>
</div>
@code {
[Parameter]
public string Title { get; set; } = "Counter Component";
[Parameter]
public int InitialCount { get; set; } = 0;
[Parameter]
public EventCallback<int> OnCountChanged { get; set; }
private int Count;
private bool ShowDetails = false;
private DateTime? LastIncrementTime;
private IJSObjectReference? module;
protected override void OnInitialized()
{
Count = Initial
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related .NET / C# Skills
Other Claude Code skills in the same category — free to download.
ASP.NET Core API
Scaffold ASP.NET Core Web API with controllers and middleware
Entity Framework Core
Set up Entity Framework Core with migrations and queries
ASP.NET Auth
Configure ASP.NET Identity with JWT and cookie authentication
Minimal API
Build minimal APIs with endpoint mapping
.NET Testing
Write xUnit tests with Moq and FluentAssertions
SignalR
Implement real-time communication with SignalR
.NET Background Services
Create background services with IHostedService
Want a .NET / C# skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.