Skip to content

Instantly share code, notes, and snippets.

@conficient
Last active November 6, 2024 15:39
Show Gist options
  • Save conficient/ba98d1662c659e170ec16650acea05c8 to your computer and use it in GitHub Desktop.
Save conficient/ba98d1662c659e170ec16650acea05c8 to your computer and use it in GitHub Desktop.
Blazor Modal Dialog with no JS interop
<button class="btn btn-primary" @onclick="@ModalShow">Show Dialog!</button>
@if (showModal)
{
<div class="modal fade show" id="myModal" style="display:block" aria-modal="true" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Confirm action</h4>
<button type="button" class="close" @onclick="@ModalCancel">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<p>This is the modal content!</p>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn" @onclick="@ModalCancel">Cancel</button>
<button type="button" class="btn btn-danger" @onclick=@ModalOk>Delete</button>
</div>
</div>
</div>
</div>
}
<hr />
@code
{
bool showModal = false;
void ModalShow() => showModal = true;
void ModalCancel() => showModal = false;
void ModalOk()
{
Console.WriteLine("Modal ok");
showModal = false;
}
}
@CuvinStefanCristian
Copy link

Thank you so much! Easiest solution out there.. This is helping my final project at university!

@Adomovic
Copy link

Adomovic commented Aug 1, 2021

Perfect,

@conficient
Copy link
Author

conficient commented Oct 5, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment