Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close a Mudblazor Dialog

I am using Mudblazor in my Blazor app. I have the following code in a component inside ValidSubmit handler:

public async Task HandleValidSubmit()
{
    DialogService.Show<SavingDialog>("Saving Data");
    await Http.PostAsJsonAsync("api/Client/AddClient", CModel);

    //close the dialog here...
    //DialogService.Close(<need reference here>);
}

The DialogService opens the SavingDialog which is also a component. After the http call, I want to close the dialog. How do I do that? I can see the DialogService.Close(DialogReference dialog) in the documentation.

How do I get reference to the dialog box that I opened so I can close it?

like image 779
user3656651 Avatar asked Aug 27 '26 14:08

user3656651


1 Answers

Show returns a reference to the opened dialog!

So all you need to do is this:

public async Task HandleValidSubmit()
{
   var dialogRef = DialogService.Show<SavingDialog>("Saving Data");
   await Http.PostAsJsonAsync("api/Client/AddClient", CModel);

   //close the dialog here...
   dialogRef.Close();
}
like image 130
faso Avatar answered Aug 31 '26 07:08

faso



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!