Blazor Bootstrap: Modal Component Examples
Modal Usage:
<Button Color="ButtonColor.Primary" @onclick="(async () => { await ShowModalAsync(); })">Show Modal</Button>
<Modal @ref="modal"
OnShowing="OnModalShowingAsync"
OnShown="OnModalShownAsync"
OnHiding="OnModalHidingAsync"
OnHidden="OnModalHiddenAsync"
OnHidePrevented="OnModalHidePreventedAsync">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @onclick="(async () => { await HideModalAsync(); })">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</Modal>
@code {
private Modal modal;
private async Task ShowModalAsync()
{
await modal?.ShowAsync();
}
private async Task HideModalAsync()
{
await modal?.HideAsync();
}
private async Task OnModalShowingAsync()
{
await Task.Run(() => { Console.WriteLine("Event: Showing"); });
}
private async Task OnModalShownAsync()
{
await Task.Run(() => { Console.WriteLine("Event: Show"); });
}
private async Task OnModalHidingAsync()
{
await Task.Run(() => { Console.WriteLine("Event: Hiding"); });
}
private async Task OnModalHiddenAsync()
{
await Task.Run(() => { Console.WriteLine("Event: Hide"); });
}
private async Task OnModalHidePreventedAsync()
{
await Task.Run(() => { Console.WriteLine("Event: Hide Prevented"); });
}
}
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
-
CreatedNov 28, 2021
-
UpdatedDec 12, 2021
-
Views2,457
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: Alert Component Examples
Blazor Bootstrap: Icon Component Examples
Blazor Bootstrap: Toasts 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