简体   繁体   English

Mudblazor 对话框 - 关闭时刷新

[英]Mudblazor dialog - Refresh on close

I am using Mudblazor in my Blazor app.我在我的 Blazor 应用程序中使用 Mudblazor。 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:使用非常简单的 AddNewAppDialog 组件代码:

<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?关闭对话框时如何在父组件中获取事件?

You have to use await dialog.Result;您必须使用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 https://mudblazor.com/components/dialog#passing-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM