I try to used mud dialog to added or edit data which displaying in MudTables
. When I added new data or edit excisting my tables not refreshing after close dialog. Only after press F5
I can see updated dataset.
My Dialog method :
private async Task OpenDialog(TaxesModel tax = null){
var parameters = new DialogParameters{{ nameof(TaxDialog.Model), tax}};
DialogService.Show<TaxDialog>(nameof(TaxDialog).Humanize(), parameters);
//reload list of taxes
await GetTaxesAsync();
StateHAsChanged();
}
In this case StateHAsChanged()
not refreshed page. But in another cases without dialog it's work fine.
CodePudding user response:
You are refreshing the data as soon as the dialog opens, before any change has happened yet to the database. After the call to DialogService.Show
the execution continues immidiately to the next line await GetTaxesAsync()
.
You need to wait for dialog to close and then fetch the new data.
private async Task OpenDialog(TaxesModel tax = null){
var parameters = new DialogParameters{ { nameof(TaxDialog.Model), tax } };
var dialog = DialogService.Show<TaxDialog>(nameof(TaxDialog).Humanize(), parameters);
// wait for the dialog to close
// execution is stopped here until the dialog returns a result
var result = await dialog.Result;
if (!result.Cancelled)
{
await GetTaxesAsync();
// StateHasChanged call is not needed I think
//StateHasChanged();
}
}