Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading