Class SfDialogService
A class that represents the dialog utility service which is used to configure built-in dialog options.
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.
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 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 specifies the text to be displayed in the alert dialog. |
System.String | title | Optional. A string specifies the title to be displayed in the alert dialog. |
DialogOptions | options | Optional. A DialogOptions specifies the options to configure alert dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task representing the asynchronous operation. |
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 specifies the text to be displayed in the confirmation dialog. |
System.String | title | Optional. A string specifies the title to be displayed in the confirmation dialog. |
DialogOptions | options | Optional. A DialogOptions specifies the options to configure confirm dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | Returns a boolean value which specifies which button is clicked by user. |
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. Where the user enters a string content, it returns when clicked OK and null when clicked Cancel.
Declaration
public Task<string> PromptAsync(string content, string title = null, DialogOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string specifies the text to be displayed in the prompt dialog. |
System.String | title | Optional. A string specifies the title to be displayed in the prompt dialog. |
DialogOptions | options | Optional. A DialogOptions specifies the options to configure prompt dialog. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | Returns a string entered by the user when the user clicks |
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 the canceled dialog box.");
}
else
{
Console.WriteLine($"The User's input is returned as \"{promptText}\".");
}