ARG.RABBI.Sonner.NetCore
1.0.5
dotnet add package ARG.RABBI.Sonner.NetCore --version 1.0.5
NuGet\Install-Package ARG.RABBI.Sonner.NetCore -Version 1.0.5
<PackageReference Include="ARG.RABBI.Sonner.NetCore" Version="1.0.5" />
<PackageVersion Include="ARG.RABBI.Sonner.NetCore" Version="1.0.5" />
<PackageReference Include="ARG.RABBI.Sonner.NetCore" />
paket add ARG.RABBI.Sonner.NetCore --version 1.0.5
#r "nuget: ARG.RABBI.Sonner.NetCore, 1.0.5"
#:package ARG.RABBI.Sonner.NetCore@1.0.5
#addin nuget:?package=ARG.RABBI.Sonner.NetCore&version=1.0.5
#tool nuget:?package=ARG.RABBI.Sonner.NetCore&version=1.0.5
Sonner.NetCore
An elegant, robust, and lightweight toaster library for .NET Core MVC and Razor Pages. Inspired by the popular React library Sonner, but built from the ground up for backend-driven .NET web applications.
(Preview of the Toast)
By ARG RABBI - Visit Profile
🚀 Features
- Framework Support: Native support for .NET 5.0, 6.0, 7.0, 8.0, and .NET 9.0.
- Full Positioning Support: Choose from 6 different positions.
- Stacking & Expanding: Sophisticated stacking logic that expands on hover.
- Rich Colors: Vibrant background colors for success, error, info, and warning states.
- Dark Theme: Built-in support for dark mode.
- Close Button: Optional dismiss button for individual toasts.
- No React/Vue required! Pure Vanilla JS and CSS natively integrated into .NET.
- Trigger Toasts from C#: Seamlessly add toasts directly from your Controllers.
- Tag Helper Integration: Clean syntax in Razor views.
📦 Installation
Via NuGet Package Manager Console:
Install-Package ARG.RABBI.Sonner.NetCore
Via .NET CLI:
dotnet add package ARG.RABBI.Sonner.NetCore
💻 Setup Guide
Follow these simple steps to integrate Sonner into your .NET application.
1. Register the Middleware
This serves the embedded assets. Choose the guide based on your project style:
Modern Hosting Style (.NET 6, 7, 8, & 9)
Usually found in Program.cs (Top-level statements).
app.UseRouting();
// Add this line after UseRouting() but before UseAuthorization()
app.UseSonner();
app.UseAuthorization();
Legacy Hosting Style (.NET 5 and below)
Usually found in Startup.cs (Configure method).
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
// Add this line
app.UseSonner();
app.UseAuthorization();
}
2. Add Tag Helpers (_ViewImports.cshtml)
Add the Sonner namespace to your Views/_ViewImports.cshtml:
@addTagHelper *, Sonner.NetCore
3. Initialize in Layout (_Layout.cshtml)
Include the CSS in <head> and the script + tag helper before </body>.
<head>
<link rel="stylesheet" href="~/sonner.css" />
</head>
<body>
@RenderBody()
<script src="~/sonner.js"></script>
<sonner-toaster
position="BottomRight"
expand="false"
rich-colors="true"
close-button="true"
theme="light">
</sonner-toaster>
</body>
🎨 Positioning
Sonner.NetCore supports 6 positions out of the box:
TopLeftTopCenterTopRightBottomLeftBottomCenterBottomRight
<sonner-toaster position="TopCenter"></sonner-toaster>
🔥 Usage (Backend)
Trigger toasts directly from your Controllers using extension methods.
public IActionResult Save()
{
// Simple toast
this.AddSuccessToast("Data saved successfully!");
// Toast with title
this.AddErrorToast("Please check your input.", "Validation Error");
// Toast with custom position override
this.AddWarningToast("Attention required!", position: ToasterPosition.TopRight);
// Custom toast
this.AddToast("Info message", ToastType.Info, position: ToasterPosition.BottomLeft);
return RedirectToAction("Index");
}
⚡ Usage (Frontend)
You can also trigger toasts manually from JavaScript using the global window.sonnerInstance. Per-toast position overrides the global configuration.
// Success toast with default position
window.sonnerInstance.toast('Operation completed!', 'Success', 'Success Title');
// Error toast with specific position override
window.sonnerInstance.toast('Something went wrong.', 'Error', null, 'top-center');
📜 Publishing Update
To publish a new version:
- Update version in
.csproj. - Run
dotnet pack -c Release. - Upload
.nupkgto NuGet.org.
Crafted with ❤️ by ARG RABBI for the robust .NET ecosystem.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.