Skip to main content
All docs
V25.1
  • IToastNotificationService.ShowToast(ToastOptions, RenderFragment) Method

    Creates and shows a toast notification with the specified options and a template.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    void ShowToast(
        ToastOptions toastOptions,
        RenderFragment template
    )

    Parameters

    Name Type Description
    toastOptions ToastOptions

    An object that contains toast options.

    template RenderFragment

    The template content.

    Remarks

    Call the ShowToast method to create and show a toast in code. Use the method parameters to set up the toast settings and add a template to the toast.

    <DxButton Text="Show a toast" Click="AddToast" />
    <DxButton Text="Hide a toast" Click="HideToast" />
    <DxToastProvider DisplayTime="@TimeSpan.Zero" ThemeMode = "ToastThemeMode.Pastel" />
    
    @code {
        [Inject] IToastNotificationService ToastService { get; set; }
    
        RenderFragment buttons = builder => {
            builder.OpenComponent<DxButton>(0);
            builder.AddAttribute(1, "Text", "button 1");
            builder.CloseComponent();
            builder.OpenComponent<DxButton>(2);
            builder.AddAttribute(3, "Text", "button 2");
            builder.AddAttribute(4, "RenderStyleMode", ButtonRenderStyleMode.Outline);
            builder.CloseComponent();
        };
    
        private void AddToast() {
            ToastService.ShowToast(new ToastOptions {
                Id = "TaskNotification",
                Title = "Toast with buttons"
            }, buttons);
        }
        private void HideToast() {
            ToastService.CloseToast("TaskNotification");
        }
    }
    

    Templated toast notification

    See Also