I am aware of Blazored Modal and this answer, but I do not want to have a specific component just for showing modals (lack of flexibility) and want to implement the code in various components myself.
Here is a very simple code to show a sample modal:
@page "/fetchdata"
<button class="btn btn-primary" @onclick="@(() => { showModal = true; })">Show Dialog!</button>
@if (showModal)
{
<div class="modal-backdrop fade show" tabindex="-1" role="dialog" style="display: block;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
}
<hr />
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from the server.</p>
@code {
bool showModal = false;
}
The code works but there is a problem with opacity:
Putting style="opacity:1;"
on <div class="modal-dialog" role="document">
also does not resolve the problem (though giving the opacity
, values lower than 1 makes it more transparent!)
What is the cause of the problem and how it can be fixed?