Blazor Bootstrap: Alert Component Examples
Alerts
Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight colors.
<div>
<Alert Color="AlertColor.Primary"> A simple primary alert. </Alert>
<Alert Color="AlertColor.Secondary"> A simple secondary alert. </Alert>
<Alert Color="AlertColor.Success"> A simple success alert. </Alert>
<Alert Color="AlertColor.Danger"> A simple danger alert. </Alert>
<Alert Color="AlertColor.Warning"> A simple warning alert. </Alert>
<Alert Color="AlertColor.Info"> A simple info alert. </Alert>
</div>
Additional Content
Alerts can also contain additional HTML elements like headings, paragraphs and dividers.
<div>
<Alert Color="AlertColor.Success">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</Alert>
</div>
Icons
Similarly, you can use Bootstrap Icons to create alerts with icons.
<div>
<Alert Color="AlertColor.Primary"> <Icon Name="IconName.InfoCircleFill" class="me-2"></Icon>An example alert with an icon </Alert>
<Alert Color="AlertColor.Success"> <Icon Name="IconName.CheckCircleFill" class="me-2"></Icon>A simple success alert with an icon </Alert>
<Alert Color="AlertColor.Danger"> <Icon Name="IconName.ExclamationTriangleFill" class="me-2"></Icon>A simple danger alert with an icon </Alert>
<Alert Color="AlertColor.Warning"> <Icon Name="IconName.ExclamationTriangleFill" class="me-2"></Icon>A simple warning alert with an icon </Alert>
</div>
Dismissing
Using the Dismissable="true"
, it's possible to dismiss any alert inline.
<div>
<Alert Color="AlertColor.Warning" Dismissable="true"> <strong>Holy guacamole!</strong> You should check in on some of those fields below. </Alert>
</div>
Manually we can close an alert with button click.
<div>
<Alert @ref="warningAlert" Color="AlertColor.Warning">
<strong>Holy guacamole!</strong> You should check in on some of those fields below. <Button Color="ButtonColor.Primary" @onclick="CloseAlert">Close</Button>
</Alert>
</div>
Blazor Bootstrap Links:
- Blazor Bootstrap: Quick Start
- Blazor Bootstrap: Alert Component Examples
- Blazor Bootstrap: Buttons Examples
- Blazor Bootstrap: Icons Component Examples
- Blazor Bootstrap: Modal Component Examples
- Blazor Bootstrap: Offcanvas Component Example
- Blazor Bootstrap: Toasts Component Examples
- Blazor Bootstrap: Tooltip Component Examples
-
CreatedDec 11, 2021
-
UpdatedDec 21, 2021
-
Views3,435
Related Articles
Fixed: Blazor Webassembly - Google Authentication Issue - Access to XMLHttpRequest at 'https://login.microsoftonline.com/.well-known/openid-configuration' from origin 'https://localhost:7215' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Blazor Bootstrap: Tooltip Component Examples
Blazor Bootstrap: Icon Component Examples
Blazor Bootstrap: Toasts Component Examples
Blazor Bootstrap: Modal Component Examples
Blazor Bootstrap: Offcanvas examples
Blazor Bootstrap: Button Examples
Blazor Bootstrap: Quick Start
How to migrate Blazor WebAssembly App to .NET 5
Blazor: How to bind employees to table / grid