Is EventCallBack possible in Blazored Modal? #280
Unanswered
nagtilaklaxman
asked this question in
Q&A
Replies: 1 comment
-
That should be possible, see the following code snippets. I used the index.razor @page "/"
<h1>Blazored Modal Sample</h1>
<hr class="mb-5" />
<p>
This is an example of using Blazored Modal in its most simplistic form.
</p>
<div class="card mb-4">
<div class="card-body">
<p class="card-text">
<code>
@("Modal.Show<Confirm>(\"Welcome to Blazored Modal\", options);")
</code>
</p>
</div>
</div>
<button @onclick="ShowModal" class="btn btn-primary">Show Modal</button>
@code {
[CascadingParameter] public IModalService Modal { get; set; }
void ShowModal()
{
var parameters = new ModalParameters();
parameters.Add(nameof(Confirm.Callback), EventCallback.Factory.Create<string>(this, CallbackFromModal));
Modal.Show<Confirm>("Welcome to Blazored Modal", parameters);
}
private void CallbackFromModal(string value)
{
Console.WriteLine(value);
}
} The component: <div>
<p>Please click one of the buttons below to close or cancel the modal.</p>
<button @onclick="UseCallback" class="btn btn-danger">Callback</button>
<button @onclick="Close" class="btn btn-primary">Close</button>
<button @onclick="Cancel" class="btn btn-secondary">Cancel</button>
</div>
@code {
[CascadingParameter] BlazoredModalInstance BlazoredModal { get; set; }
[Parameter]
public EventCallback<string> Callback { get; set; }
async Task Close() => await BlazoredModal.CloseAsync(ModalResult.Ok(true));
async Task Cancel() => await BlazoredModal.CancelAsync();
async Task UseCallback() => await Callback.InvokeAsync("test 1 2 3");
} If you place a breakpoint in the Hopefully this answers your question. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is EventCallBack possible in Blazored Modal?
I want to pass some event information to parent component without closing the model.
Beta Was this translation helpful? Give feedback.
All reactions