ToastService

The ToastService is a service that can be used to show toasts. It can be injected into a page and used to show different type of toasts.

For a component to be useable by the ToastService, it needs to implement IToastContentComponent<T> where T represent the type of the data to be shown in the toast.

The ToastService is automatically registered in the DI container with the AddFluentUIComponents() call.

Toast container

Toasts are rendered through the <FluentToastProvider /> component. This component needs to be added to the main layout of your application/site. You typically do this in the MainLayout.razor file at the end of the <main> section like this:

<main>
    <nav>
        <!-- -->
    </nav>
    <div class="content">
        <article id="article">
            @Body
        </article>
    </div>
    <FluentToastProvider MaxToastCount="10" />
</main>

IMPORTANT!!

For the <FluentToastProvider/> to work properly, it needs interactivity! If you are using "per page" interactivity or ASP.NET Core 8 or above with Server Side Rendering , make sure to add a @rendermode to either the provider itself or the component the provider is placed in.

See the documentation below for more information about the FluentToastProvider parameters.

Examples

See the toast page for examples of the different types of available toasts:

  • Confirmation toast
  • Communication toast
  • Progress toast

Documentation

ToastService Class

Methods

Name
Parameters
Type
Description
ClearAllbool includeQueue
void
Removes all toasts
ClearCustomIntentToastsbool includeQueue
void
Removes all toasts with toast intent Custom
ClearDownloadToastsbool includeQueue
void
Removes all toasts with toast intent Download
ClearErrorToastsbool includeQueue
void
Removes all toasts with toast intent Error
ClearEventToastsbool includeQueue
void
Removes all toasts with toast intent Event
ClearInfoToastsbool includeQueue
void
Removes all toasts with toast intent Info
ClearIntentToastIntent intent
bool includeQueue
void
Removes all toasts with a specified intent.
ClearMentionToastsbool includeQueue
void
Removes all toasts with toast intent Mention
ClearProgressToastsbool includeQueue
void
Removes all toasts with toast intent Progress
ClearQueuevoid
Removes all queued toasts
ClearQueueCustomIntentToastsvoid
Removes all queued toasts with toast intent Custom
ClearQueueDownloadToastsvoid
Removes all queued toasts with toast intent Download
ClearQueueErrorToastsvoid
Removes all queued toasts with toast intent Error
ClearQueueEventToastsvoid
Removes all queued toasts with toast intent Event
ClearQueueInfoToastsvoid
Removes all queued toasts with toast intent o
ClearQueueMentionToastsvoid
Removes all queued toasts with toast intent Mention
ClearQueueProgressToastsvoid
Removes all queued toasts with toast intent Progress
ClearQueueSuccessToastsvoid
Removes all queued toasts with toast intent Success
ClearQueueToastsToastIntent intent
void
Removes all queued toasts with a specified intent.
ClearQueueUploadToastsvoid
Removes all queued toasts with toast intent Upload
ClearQueueWarningToastsvoid
Removes all queued toasts with toast intent Warning
ClearSuccessToastsbool includeQueue
void
Removes all toasts with toast intent Success
ClearUploadToastsbool includeQueue
void
Removes all toasts with toast intent Upload
ClearWarningToastsbool includeQueue
void
Removes all toasts with toast intent Warning
CloseToaststring id
void
ShowCommunicationToastToastParameters<CommunicationToastContent> parameters
void
ShowConfirmationToastToastParameters<ConfirmationToastContent> parameters
void
ShowCustomstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
(Icon Value, Color Color)? icon
void
Shows a simple custom confirmation toast.
Only shows icon, title and close button or action.
ShowDownloadstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple download confirmation toast.
Only shows icon, title and close button or action.
ShowErrorstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple error confirmation toast.
Only shows icon, title and close button or action.
ShowEventstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple event confirmation toast.
Only shows icon, title and close button or action.
ShowInfostring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple information confirmation toast.
Only shows icon, title and close button or action.
ShowMentionstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple mention confirmation toast.
Only shows icon, title and close button or action.
ShowProgressstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple progress confirmation toast.
Only shows icon, title and close button or action.
ShowProgressToastToastParameters<ProgressToastContent> parameters
void
ShowSuccessstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple succes confirmation toast.
Only shows icon, title and close button or action.
ShowToastToastIntent intent
string title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a toast using the supplied parameters
ShowToast<T, TData>ToastParameters<TData> parameters
void
Shows the toast with the component type
ShowToast<TContent>Type component
ToastParameters parameters
TContent content
void
Shows a toast with the component type as the body,
passing the specified parameters
ShowUploadstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple upload confirmation toast.
Only shows icon, title and close button or action.
ShowWarningstring title
int? timeout
string topAction
EventCallback<ToastResult>? callback
void
Shows a simple warning confirmation toast.
Only shows icon, title and close button or action.
UpdateToast<TContent>string id
ToastParameters<TContent> parameters
void
Updates a toast

FluentToastProvider Class

Parameters

Name
Type
Default
Description
MaxToastCountint
4
Gets or sets the maximum number of toasts that can be shown at once. Default is 4.
PositionToastPosition
TopRight
Gets or sets the position on screen where the toasts are shown. See ToastPosition
Default is ToastPosition.TopRight
RemoveToastsOnNavigationbool
True
Gets or sets whether to remove toasts when the user navigates to a new page. Default is true.
ShowCloseButtonbool
True
Gets or sets whether to show a close button on a toast. Default is true.
[Obsolete('This parameter will be removed in a future version. It is and should not not used.')]
Timeoutint
7000
Gets or sets the number of milliseconds a toast remains visible. Default is 7000 (7 seconds).

Methods

Name
Parameters
Type
Description
RemoveToaststring toastId
void
BottomLeft
BottomStart
BottomCenter
BottomRight
BottomEnd
TopLeft
TopStart
TopCenter
TopRight
TopEnd
An error has occurred. This application may no longer respond until reloaded. Reload 🗙