Blazor.Toast 1.0.2

dotnet add package Blazor.Toast --version 1.0.2
                    
NuGet\Install-Package Blazor.Toast -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazor.Toast" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blazor.Toast" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Blazor.Toast" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blazor.Toast --version 1.0.2
                    
#r "nuget: Blazor.Toast, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blazor.Toast@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazor.Toast&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Blazor.Toast&version=1.0.2
                    
Install as a Cake Tool

Blazor.Toast

A lightweight toast notification library for Blazor, built for .NET 10 and modern Razor Components.

Independent fork — original project: https://github.com/Blazored/Toast (MIT). This fork adapts the library for .NET 10 and provides a streamlined API.


Quick summary

  • Lightweight toast library for Blazor apps
  • Minimal, consistent public API (RenderFragment-first)
  • Compatible with .NET 10 Razor Components
  • Supports icons, progress bar, close button, component-based toasts, and awaitable results

Installation

Add the NuGet package (when published) or reference the project directly:

dotnet add package Blazor.Toast

Or add a project reference to your solution.


Service registration

Register the toast service in DI in your Program.cs (Server or WASM hosting as appropriate):

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents(); // for interactive server render mode

builder.Services.AddBlazorToast();

var app = builder.Build();
// ... map components and run

The extension AddBlazorToast() registers the concrete ToastService as a singleton and exposes IToastService (public API) and the internal IToastServiceEvents used by the rendering component.


Usage

  1. Add helpful usings to _Imports.razor:
@using Blazor.Toast
@using Blazor.Toast.Services
@using Blazor.Toast.Configuration
  1. Place the <Toasts> component somewhere in your layout (must be rendered in an interactive render mode):
@rendermode InteractiveServer
<Toasts Position="ToastPosition.TopRight" Timeout="8" ShowProgressBar="true" />

If you prefer, render a small child component that contains <Toasts> with an explicit @rendermode attribute.

  1. Show a toast from any component by injecting IToastService:

RenderFragment-based (preferred):

@inject IToastService ToastService

@code {
    void Save()
    {
        ToastService.ShowSuccess(builder => builder.AddContent(0, "Saved"));
    }
}

String convenience overloads are provided as extension methods so older code that passes a string still works:

ToastService.ShowSuccess("Saved"); // uses extension to wrap as RenderFragment

Quick comparison — fire-and-forget vs await simple vs await detailed:

// 1) Fire-and-forget: show and continue immediately
ToastService.ShowInfo(builder => builder.AddContent(0, "Saved successfully"));

// 2) Await simple close reason (enum)
var reason = await ToastService.ShowInfoAsync(builder => builder.AddContent(0, "Confirm action?"));
if (reason == ToastCloseReason.Click)
{
    // user clicked the toast body
}

// 3) Await detailed result (includes timestamps and id)
var result = await ToastService.ShowInfoDetailedAsync(builder => builder.AddContent(0, "Please confirm"));
Console.WriteLine($"Toast {result.ToastId} closed with {result.Reason} after {result.Duration.TotalSeconds}s");

Brief public API (high level)

IToastService focuses on RenderFragment messages and component-based toasts. Key methods:

  • Message-based (RenderFragment)

    • void ShowInfo(RenderFragment message, Action<ToastSettings>? settings = null)
    • Task<ToastCloseReason> ShowInfoAsync(RenderFragment message, Action<ToastSettings>? settings = null)
    • Task<ToastResult> ShowInfoDetailedAsync(RenderFragment message, Action<ToastSettings>? settings = null)
  • Component-based

    • void ShowToast<TComponent>(ToastParameters? parameters = null, Action<ToastSettings>? settings = null) where TComponent : IComponent
    • Task<ToastCloseReason> ShowToastAsync<TComponent>(ToastParameters? parameters = null, Action<ToastSettings>? settings = null) where TComponent : IComponent
    • Task<ToastResult> ShowToastDetailedAsync<TComponent>(ToastParameters? parameters = null, Action<ToastSettings>? settings = null) where TComponent : IComponent
  • Clear / queue APIs

    • void ClearAll(), void ClearToasts(ToastLevel level), void ClearCustomToasts(), void ClearQueue(), void ClearQueueToasts(ToastLevel level)

See sample pages in the WebAppSample project for many usage examples.


ToastCloseReason and ToastResult

When you await ShowXAsync(...) you receive a ToastCloseReason (enum) indicating how the toast was closed:

  • Unknown, Timeout, CloseButton, Click, Programmatic

When you await ShowXDetailedAsync(...) you receive a ToastResult with:

  • ToastId (Guid), Reason (ToastCloseReason), ShownAt, ClosedAt, and computed Duration.

These let you react to user interactions or programmatic clears.


Component-based toasts and cascading Toast

Render a Blazor component inside a toast and await the detailed ToastResult. The component receives a cascading Toast instance which it can use to close itself (ParentToast.Close()). See WebAppSample for examples.


Backward compatibility & migration notes

  • The public API was simplified to prefer RenderFragment messages. To avoid breaking callers that pass strings, extension helpers are included that wrap strings into RenderFragment automatically.
  • Internal event hooks previously exposed are now internal (IToastServiceEvents) and should not be consumed directly. The public API methods should be used instead.
  • If you relied on deprecated overloads that returned ToastResult via a detailedResult boolean, use the explicit ShowXDetailedAsync methods instead.

Examples and samples

See the WebAppSample project for multiple example pages:

  • ToastGeneralExample.razor — general usage
  • ToastCloseReasonExample.razor — demonstrates all close reasons and awaitable close
  • ToastResultExample.razor — demonstrates ToastResult detailed output

Origin

This project is based on the following repository:

https://github.com/Blazored/Toast

This is an independent modification to support .NET 10. All original credit remains with the upstream contributors under the MIT License.


License

MIT License
See the license.txt file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 263 2/22/2026
1.0.1 122 2/22/2026 1.0.1 is deprecated.

MAJOR.MINOR.PATCH