Alert

in namespace DotVVM.Controls.Tailwind.Controls

Displays contextual feedback messages for users.

Usage & Scenarios

Renders contextual alert messages with semantic styles, optional headers, and dismiss support. The alert body can use plain text or custom child content.

Basic Alert

Shows a simple default alert with text message.

<t:Alert Text="This is a basic alert." />

Alert types

Shows all available alert visual types: Default, Primary, Info, Success, Warning and Danger. Use these to communicate different levels of importance to the user.

<div class="flex flex-col gap-4">
    <t:Alert Type="Default" Text="Default alert" />
    <t:Alert Type="Primary" Text="This is a primary alert — check it out!" />
    <t:Alert Type="Info" Text="This is an info alert — check it out!" />
    <t:Alert Type="Success" Text="This is a success alert — check it out!" />
    <t:Alert Type="Warning" Text="This is a warning alert — check it out!" />
    <t:Alert Type="Danger" Text="This is a danger alert — check it out!" />
</div>

Dismissible alert

An alert configured with IsDismissible="true". The sample shows how to dismiss the alert and reset it via a button.

<div class="flex flex-col gap-4">
    <t:Alert Type="Info" Text="Click the × to dismiss this alert." IsDismissible="true" IsDismissed="{value: AlertDismissed}" Dismissed="{command: DismissAlert()}" />
    <t:Button Text="Reset" Click="{command: ResetAlert()}" Size="Small" />
</div>

using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public bool AlertDismissed { get; set; } = false;

    public void DismissAlert()
    {
        AlertDismissed = true;
    }

    public void ResetAlert()
    {
        AlertDismissed = false;
    }
}

Bindable alert type and text

Shows how to bind the Type of the alert to a ViewModel property and how to bind the alert Text to a TextBox value. Use the small buttons to change the alert type.

<div class="flex flex-col gap-4">
    <t:Alert Type="{value: SelectedAlertType}" Text="This alert type is bound to a property." />
    <div class="flex gap-2 flex-wrap">
        <t:Button Text="Default" Click="{command: SetAlertType(0)}" Size="Small" />
        <t:Button Text="Primary" Click="{command: SetAlertType(5)}" Size="Small" />
        <t:Button Text="Success" Click="{command: SetAlertType(1)}" Size="Small" />
        <t:Button Text="Info" Click="{command: SetAlertType(4)}" Size="Small" />
        <t:Button Text="Warning" Click="{command: SetAlertType(2)}" Size="Small" />
        <t:Button Text="Danger" Click="{command: SetAlertType(3)}" Size="Small" />
    </div>
</div>

using DotVVM.Controls.Tailwind.Controls;
using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public AlertType SelectedAlertType { get; set; } = AlertType.Info;


    public void SetAlertType(int typeValue)
    {
        SelectedAlertType = (AlertType)typeValue;
    }
}

Bindable Alert Text

Demonstrates binding the alert message text to a viewmodel property, allowing dynamic updates through a text input field.

<div class="flex flex-col gap-4">
    <t:Alert Type="Info" Text="{value: AlertMessage}" />
    <dot:TextBox Text="{value: AlertMessage}" placeholder="Type a message..." class="p-2 border border-gray-300 rounded-md" />
</div>

using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public string AlertMessage { get; set; } = "This message can be edited!";
}

Alert with Custom Content

Demonstrates using custom HTML and DotVVM controls inside the alert body instead of the Text property.

<div class="flex flex-col gap-4">
    <t:Alert Type="Success">
        <strong>Great success!</strong> This content is placed inside the alert tags instead of using the Text property.
    </t:Alert>
    <t:Alert Type="Warning">
        You can use <em>any HTML</em> or <strong>DotVVM controls</strong> inside the alert body.
    </t:Alert>
</div>

Properties

Name Type Description Notes Default Value
property icon Content List<DotvvmControl> Gets or sets custom alert body content.
attribute
inner element
static value
bindable
default
null
property icon HeaderTemplate ITemplate Gets or sets the custom content rendered in the alert header.
attribute
inner element
static value
bindable
default
null
property icon HeaderText String Gets or sets the text displayed in the alert header.
attribute
inner element
static value
bindable
default
null
property icon IsDismissed Boolean Controls whether a dismissible alert is currently hidden.
attribute
inner element
static value
bindable
default
null
property icon IsDismissible Boolean Determines whether the alert renders a close button.
attribute
inner element
static value
bindable
default
False
property icon Text String Gets or sets the alert message text.
attribute
inner element
static value
bindable
default
null
property icon Type AlertType Selects the visual style of the alert.
attribute
inner element
static value
bindable
default
Default
property icon Visible Boolean Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon Dismissed ICommandBinding Command invoked when the close button is clicked.

HTML produced by the control