No results
1
Toast
Byron edited this page 2026-10-02 23:40:42 +02:00
Table of contents
Warning
Don't forget to include the
toast.jsfile whenever you want to use toasts:
<script src="@(Assets["_content/CleanUI/toast.js"])"></script>You also have to add the
<CleanToasts />components to your app. It's recommended to do this in yourApp.razor, or your main layout.
Basic
Important
This example requires the
Interactiverendering mode.
@using Microsoft.JSInterop
<CleanButton class="mie-sm" @onclick="@(() => ShowToast(CleanToastType.Info))">
Show info toast
</CleanButton>
<CleanButton class="mie-sm" @onclick="@(() => ShowToast(CleanToastType.Success))">
Show success toast
</CleanButton>
<CleanButton class="mie-sm" @onclick="@(() => ShowToast(CleanToastType.Warning))">
Show warning toast
</CleanButton>
<CleanButton class="mie-sm" @onclick="@(() => ShowToast(CleanToastType.Danger))">
Show danger toast
</CleanButton>
@code {
private readonly IJSRuntime js;
public Basic(IJSRuntime js) =>
this.js = js;
private void ShowToast(CleanToastType type) =>
_ = js.ShowToastAsync(new CleanToastDescriptor(type, "Hello world!", "This is a toast notification."));
}
Static rendering mode support
Note
Use the
CleanToast.Show()andCleanToast.Hide()methods to generate a JavaScript-invokable string to show- and hide toasts respectively.
<CleanButton onclick="@(CleanToast.Show(new CleanToastDescriptor(CleanToastType.Info, "Hello world!", "This is a toast notification.")))">
Show info toast
</CleanButton>
<CleanButton onclick="@(CleanToast.Show(new CleanToastDescriptor(CleanToastType.Success, "Hello world!", "This is a toast notification.")))">
Show success toast
</CleanButton>
<CleanButton onclick="@(CleanToast.Show(new CleanToastDescriptor(CleanToastType.Warning, "Hello world!", "This is a toast notification.")))">
Show warning toast
</CleanButton>
<CleanButton onclick="@(CleanToast.Show(new CleanToastDescriptor(CleanToastType.Danger, "Hello world!", "This is a toast notification.")))">
Show danger toast
</CleanButton>