Bootstrap 4 modal dialog for Asp.NET Blazor
Bootstrap 4, usually included with default Blazor template.
- Install BlazorBootstrap.Modal from NuGet by PowerShell:
or via
Install-Package BlazorBootstrap.Modal
dotnet
CLIdotnet add package BlazorBootstrap.Modal
- Register services in
Startup.cs
services.AddBootstrapModal();
- Add modal to layout
MainLayout.razor
file<BootstrapModal />
-
Create modal dialog, for example
SimpleModal.razor
:<p>Simple bootstrap 4 modal.</p> <span>Parameter: @SampleParameter</span> @code{ [Parameter] string SampleParameter { get; set; } }
-
Inject modal service into your class
@inject IModal Modal
-
Invoke modal:
Modal.Show<SimpleModal>("Simple modal", ModalParameter.Get("SampleParameter", "This is a parameter"))
where the first parameter is title of the modal window and second is a list of parameters to pass to the modal class.
For more example refer to the
BlazorBootstrap.Modal.Samples
project.