Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/build-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- "aspnet-core/build-web-api-dotnet-8/**"
- "aspnet-core/caching-outputcache-redis-invalidation/**"
- "aspnet-core/minimal-apis-real-world/**"
- "blazor/create-interactive-ui-csharp-12/**"
- ".github/workflows/build-samples.yml"

pull_request:
Expand All @@ -28,6 +29,7 @@ on:
- "aspnet-core/build-web-api-dotnet-8/**"
- "aspnet-core/caching-outputcache-redis-invalidation/**"
- "aspnet-core/minimal-apis-real-world/**"
- "blazor/create-interactive-ui-csharp-12/**"
- ".github/workflows/build-samples.yml"

workflow_dispatch:
Expand Down Expand Up @@ -353,3 +355,35 @@ jobs:
aspnet-core/minimal-apis-real-world/MinimalApiPipeline.slnx
--configuration Release
--no-build

test-blazor-todo-dashboard:
name: Test Blazor Todo Dashboard sample
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v5

- name: Install .NET 10 SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"

- name: Restore
run: >
dotnet restore
blazor/create-interactive-ui-csharp-12/BlazorTodoMinimal.slnx

- name: Build
run: >
dotnet build
blazor/create-interactive-ui-csharp-12/BlazorTodoMinimal.slnx
--configuration Release
--no-restore

- name: Test
run: >
dotnet test
blazor/create-interactive-ui-csharp-12/BlazorTodoMinimal.slnx
--configuration Release
--no-build
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Each sample folder contains a focused implementation of one tutorial topic. The
| [`aspnet-core/build-web-api-dotnet-8`](aspnet-core/build-web-api-dotnet-8/) | Minimal .NET 10 Todo API demonstrating route groups, dependency injection, CRUD status codes, validation, middleware, and integration testing | [ASP.NET Core Fundamentals: Build Web APIs on .NET 8](https://www.dotnet-guide.com/tutorials/aspnet-core/build-web-api-dotnet-8/) |
| [`aspnet-core/caching-outputcache-redis-invalidation`](aspnet-core/caching-outputcache-redis-invalidation/) | Minimal .NET 10 Catalog API demonstrating Output Cache policies, query and route variation, tag eviction, write-path invalidation, and integration testing | [ASP.NET Core Caching: Output Cache, Redis & Invalidation Strategies That Actually Work](https://www.dotnet-guide.com/tutorials/aspnet-core/caching-outputcache-redis-invalidation/) |
| [`aspnet-core/minimal-apis-real-world`](aspnet-core/minimal-apis-real-world/) | Focused .NET 10 Orders API demonstrating endpoint filters, FluentValidation, URL-segment versioning, typed results, and partitioned rate limiting | [ASP.NET Core / Minimal APIs in the Real World: Filters, Validation, Versioning & Rate Limiting](https://www.dotnet-guide.com/tutorials/aspnet-core/minimal-apis-real-world/) |
| [`blazor/create-interactive-ui-csharp-12`](blazor/create-interactive-ui-csharp-12/) | Interactive .NET 10 Todo Dashboard demonstrating Razor components, form binding, DataAnnotations validation, scoped state, EventCallback communication, filtering, and bUnit component tests | [Blazor Web Development: Create Interactive UIs with C# 12](https://www.dotnet-guide.com/tutorials/blazor/create-interactive-ui-csharp-12/) |

## Companion articles
- [Common Microsoft.Extensions.AI mistakes](https://www.dotnet-guide.com/articles/dotnet-ai/microsoft-extensions-ai-common-mistakes/)
Expand Down Expand Up @@ -122,6 +123,28 @@ tutorials/
| `-- TransactionalOutboxMinimal.Tests/
| |-- TransactionalOutboxMinimal.Tests.csproj
| `-- OutboxFlowTests.cs
|-- blazor/
| `-- create-interactive-ui-csharp-12/
| |-- BlazorTodoMinimal.slnx
| |-- README.md
| |-- src/
| | `-- BlazorTodoMinimal/
| | |-- BlazorTodoMinimal.csproj
| | |-- Program.cs
| | |-- TodoState.cs
| | `-- Components/
| | |-- _Imports.razor
| | |-- App.razor
| | |-- Routes.razor
| | |-- Pages/
| | | |-- NotFound.razor
| | | `-- Todos.razor
| | `-- Shared/
| | `-- TodoList.razor
| `-- tests/
| `-- BlazorTodoMinimal.Tests/
| |-- BlazorTodoMinimal.Tests.csproj
| `-- TodoDashboardTests.cs
|-- aspnet-core/
| |-- api-security-in-practice/
| | |-- ApiSecurityMinimal.slnx
Expand Down
8 changes: 8 additions & 0 deletions blazor/create-interactive-ui-csharp-12/BlazorTodoMinimal.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/BlazorTodoMinimal/BlazorTodoMinimal.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/BlazorTodoMinimal.Tests/BlazorTodoMinimal.Tests.csproj" />
</Folder>
</Solution>
180 changes: 180 additions & 0 deletions blazor/create-interactive-ui-csharp-12/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Blazor Interactive Todo Dashboard — Minimal Sample

A focused .NET 10 companion showing how Razor components, two-way binding,
`EditForm` validation, scoped state, child-component parameters, event callbacks,
and bUnit tests work together in an Interactive Server Blazor Web App.

## Full tutorial

[Blazor Web Development: Create Interactive UIs with C# 12](https://www.dotnet-guide.com/tutorials/blazor/create-interactive-ui-csharp-12/)

## Framework note

The tutorial explains Blazor on .NET 8 and C# 12.

This companion targets .NET 10 so it can use the DOTNET GUIDE repository's
current SDK and CI toolchain. The Razor component, binding, `EditForm`,
DataAnnotations, scoped-state, `EventCallback`, and component-testing patterns
demonstrated here are the same core Blazor concepts.

## What this sample demonstrates

- a Blazor Web App;
- global Interactive Server rendering;
- a routable Todo Dashboard;
- `EditForm` and `DataAnnotationsValidator`;
- two-way input binding;
- field validation messages;
- a scoped in-memory state service;
- component parameters;
- `EventCallback<int>`;
- `@key` for Todo list items;
- create, toggle, filter, and delete interactions;
- current route-aware Not Found handling;
- bUnit 2.x component tests.

## Interaction flow

```text
browser event
→ Razor component handler
→ validated form or EventCallback
→ scoped TodoState update
→ component re-render
```

## Render-mode boundary

The sample uses Interactive Server.

Events are processed on the server over the Blazor circuit. The browser must
maintain a connection to the application.

This sample does not provide offline support.

## State boundary

`TodoState` is registered as scoped.

In Interactive Server, scoped state is associated with the user's circuit. The
state is not a database and is not durable.

Restarting the application or replacing the circuit resets the sample.

## Prerequisite

- .NET 10 SDK
- a modern browser for manual interaction checks

Check:

```powershell
dotnet --version
```

## Restore, build, and test

```powershell
dotnet restore `
.\BlazorTodoMinimal.slnx

dotnet build `
.\BlazorTodoMinimal.slnx `
--configuration Release `
--no-restore

dotnet test `
.\BlazorTodoMinimal.slnx `
--configuration Release `
--no-build
```

## Run

```powershell
dotnet run `
--project .\src\BlazorTodoMinimal\BlazorTodoMinimal.csproj `
--urls http://localhost:5140
```

Open:

```text
http://localhost:5140/
```

## Manual checks

- add a valid Todo item;
- submit an invalid short title;
- toggle an item;
- filter active and completed items;
- delete an item;
- navigate to an unknown path.

## Testing boundary

Seven bUnit component tests render and interact with Razor components in memory.
One ASP.NET Core integration test verifies that a direct unknown-route request
returns the custom Not Found page.

They do not launch a browser or test a live SignalR connection. Browser behavior
is covered by the manual verification steps.

## Project structure

```text
BlazorTodoMinimal.slnx
README.md
src/
└── BlazorTodoMinimal/
├── BlazorTodoMinimal.csproj
├── Program.cs
├── TodoState.cs
└── Components/
├── _Imports.razor
├── App.razor
├── Routes.razor
├── Pages/
│ ├── NotFound.razor
│ └── Todos.razor
└── Shared/
└── TodoList.razor
tests/
└── BlazorTodoMinimal.Tests/
├── BlazorTodoMinimal.Tests.csproj
└── TodoDashboardTests.cs
```

## Deliberately omitted

- Interactive WebAssembly;
- Interactive Auto;
- offline/PWA support;
- JavaScript interop;
- QuickGrid;
- virtualization;
- FluentValidation;
- authentication and authorization;
- EF Core and SQLite;
- external APIs;
- browser automation;
- Docker;
- Azure deployment;
- production persistence.

These topics remain in the full tutorial or another focused companion.

## Verification

- Companion target framework: .NET 10
- Tutorial framework: .NET 8
- Render mode: Interactive Server
- Application NuGet packages: none
- External services required: none
- Database required: none
- API keys required: none
- Expected component/integration tests: 8
- Last reviewed: 2026-08-02

This sample is educational and should be reviewed before production use.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1" />

<base href="/" />

<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />

<script src="_framework/blazor.web.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@page "/not-found"

<PageTitle>Not Found</PageTitle>

<main>
<h1>Page not found</h1>

<p>
The requested page does not exist.
</p>

<a href="/">
Return to the Todo Dashboard
</a>
</main>
Loading
Loading