Class SfDialogService
A class that represents the dialog utility service which is used to configure and display built-in dialog boxes such as alert, confirmation, and prompt dialogs.
Inheritance
Namespace: Syncfusion.Blazor.Popups
Assembly: Syncfusion.Blazor.dll
Syntax
public class SfDialogService : Object
Remarks
SfDialogService can be injected using @inject SfDialogService DialogService
in any page to show the built-in dialogs.
This service provides methods to display common dialog types with customizable options and handles user interactions asynchronously.
Examples
Dialog service must be configured in the Program.cs
file for Blazor WASM App, .NET 6 Blazor Server App and
Startup.cs
file for .NET 5 and lower version Blazor Server App.
In Program.cs
dialog service can be configured like the below code:
using Syncfusion.Blazor.Popups;
. . .
builder.Services.AddScoped<SfDialogService>();
In Startup.cs
dialog service can be configured like the below code:
using Syncfusion.Blazor.Popups;
. . .
public void ConfigureServices(IServiceCollection services)
{
. . .
services.AddScoped<SfDialogService>();
}
Constructors
SfDialogService()
Declaration
public SfDialogService()
Methods
AlertAsync(String, String, DialogOptions)
Opens an alert dialog box which is used to display warning or informational messages to the users.
Declaration
public Task AlertAsync(string content, string title = null, DialogOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that specifies the text to be displayed in the alert dialog. |
System.String | title | Optional. A string that specifies the title to be displayed in the alert dialog. |
DialogOptions | options | Optional. A DialogOptions that specifies the options to configure the alert dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.Task representing the asynchronous operation that completes when the user closes the dialog. |
Remarks
This method displays a modal alert dialog that shows information to the user. The alert dialog typically contains a single OK
button for dismissal.
The method returns asynchronously and will wait for the user to acknowledge the message before continuing execution.
Examples
Code example to show alert dialog:
await DialogService.AlertAsync("Alert Dialog Content");
Console.WriteLine($"The user closed the alert dialog.");
ConfirmAsync(String, String, DialogOptions)
Opens a confirmation dialog box with two buttons as OK
and Cancel
.
Declaration
public Task<bool> ConfirmAsync(string content, string title = null, DialogOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that specifies the text to be displayed in the confirmation dialog. |
System.String | title | Optional. A string that specifies the title to be displayed in the confirmation dialog. |
DialogOptions | options | Optional. A DialogOptions that specifies the options to configure the confirmation dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | Returns a System.Boolean value which specifies which button is clicked by the user. |
Remarks
This method displays a modal confirmation dialog that requires user interaction. The dialog contains two buttons by default: OK
and Cancel
.
The method returns asynchronously and will wait for the user to make a selection before continuing execution.
Examples
Code example to show confirmation dialog:
bool isConfirm = await DialogService.ConfirmAsync("Are you sure you want to permanently delete these items?", "Delete Multiple Items");
string confirmMessage = isConfirm ? "confirmed" : "canceled";
Console.WriteLine($"The user {confirmMessage} the dialog box.");
PromptAsync(String, String, DialogOptions)
Opens a prompt dialog that prompts the user to input text.
Declaration
public Task<string> PromptAsync(string content, string title = null, DialogOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that specifies the text to be displayed in the prompt dialog. |
System.String | title | Optional. A string that specifies the title to be displayed in the prompt dialog. |
DialogOptions | options | Optional. A DialogOptions that specifies the options to configure the prompt dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | Returns a System.String entered by the user when the user clicks |
Remarks
This method displays a modal prompt dialog that allows the user to enter text input. The dialog contains an input field and typically has OK
and Cancel
buttons.
The method returns asynchronously and will wait for the user to either provide input or cancel the dialog before continuing execution.
Examples
Code example to show prompt dialog:
string promptText = await DialogService.PromptAsync("Enter your name:", "Join Chat Group", new DialogOptions()
{
PrimaryButtonOptions = new DialogButtonOptions { Content = "Okay" },
CancelButtonOptions = new DialogButtonOptions { Content = "Cancel" },
});
if (promptText == null)
{
Console.WriteLine($"The user canceled the dialog box.");
}
else
{
Console.WriteLine($"The User's input is returned as \"{promptText}\".");
}