Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mudblazor dialog - Refresh on close

I am using Mudblazor in my Blazor app. The following code opens a dialog :

private async Task OpenDialog()
{
    var options = new DialogOptions { CloseOnEscapeKey = true };
    var dialog = DialogService.Show<AddNewAppDialog>("Adding new application", options);
    
    // TODO refresh data on dialog close
}

With very simple code for AddNewAppDialog component :

<MudDialog>
<DialogContent>
    <MudTextField @bind-Value="ApplicationName" Variant="Variant.Outlined" Label="Application Name" />

</DialogContent>
<DialogActions>
    <MudButton OnClick="Cancel">Cancel</MudButton>
    <MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
</DialogActions>
@code {

    public string ApplicationName { get; set; }

    [CascadingParameter] 
    MudDialogInstance MudDialog { get; set; }

    async Task Submit()
    {
        await CreateApplication();
        MudDialog.Close(DialogResult.Ok(true));
    }

    void Cancel() => MudDialog.Cancel();

 }

How do I get an event in parent component when my dialog is closed ?

like image 747
Koks_rs Avatar asked Jul 29 '26 09:07

Koks_rs


1 Answers

You have to use await dialog.Result;:

private async Task OpenDialog()
{
    var options = new DialogOptions { CloseOnEscapeKey = true };
    var dialog = DialogService.Show<AddNewAppDialog>("Adding new application", options);
    
    // wait modal to close
    var result = await dialog.Result;

    // you can check if the modal was cancelled
    var isCancelled = result.Cancelled;
    
    // refresh your data
}

https://mudblazor.com/components/dialog#passing-data

like image 119
Dimitris Maragkos Avatar answered Jul 30 '26 23:07

Dimitris Maragkos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!