IDialogService
The IDialogService provides methods for displaying modal dialogs to the user, including confirmation prompts, error messages, informational notices, success notifications, and warnings.
Injecting the Service
Inject IDialogService into any Blazor component via property injection. Note that this is the PowerPortalsPro dialog service (PowerPortalsPro.Web.Blazor.Services.IDialogService), not the FluentUI dialog service.
using IDialogService = PowerPortalsPro.Web.Blazor.Services.IDialogService;
[Inject]
private IDialogService _dialogService { get; set; } = null!;
Confirmation Dialogs
Use ShowConfirmationAsync to prompt the user with a yes/no question. The returned DialogResult.Cancelled property is true when the user selects the secondary (negative) option.
var result = await _dialogService.ShowConfirmationAsync(
"Are you sure you want to delete this record?",
title: "Confirm Delete",
primaryText: "Yes",
secondaryText: "No");
if (!result.Cancelled)
{
// User confirmed — proceed with deletion
}
Message Dialogs
Use the following methods to show single-button message dialogs with different visual styles:
ShowInfoAsync— Informational message with a neutral icon.ShowSuccessAsync— Success message with a green checkmark icon.ShowWarningAsync— Warning message with a yellow warning icon.ShowErrorAsync— Error message with a red error icon.
await _dialogService.ShowInfoAsync("The operation completed.", "Information");
await _dialogService.ShowSuccessAsync("Record saved successfully.", "Success");
await _dialogService.ShowWarningAsync("This action cannot be undone.", "Warning");
await _dialogService.ShowErrorAsync("An error occurred while saving.", "Error");
Common Parameters
All dialog methods accept optional title and primaryText parameters. If omitted, localized default values are used. The confirmation dialog also accepts a secondaryText parameter for the cancel button label.
Dialog Result
All methods return a DialogResult object. For confirmation dialogs, check the Cancelled property to determine the user's choice. For message dialogs, the result indicates the dialog was dismissed.
Interactive Demo
Use the controls below to customize the dialog title and message, then click any button to see the corresponding dialog type.
IDialogService Interface
Methods
Name | Parameters | Type | Description |
|---|---|---|---|
ShowConfirmationAsync | string message string title string primaryText string secondaryText | Task<DialogResult> | Shows a confirmation dialog with the supplied message and two action buttons, then waits for the user to choose one. The returned Services.DialogResult has DialogResult.Cancelled set to |
ShowErrorAsync | string message string title string primaryText | Task<DialogResult> | Shows an error dialog with the supplied message and waits for the user to dismiss it. |
ShowInfoAsync | string message string title string primaryText | Task<DialogResult> | Shows an informational dialog with the supplied message and waits for the user to dismiss it. |
ShowSuccessAsync | string message string title string primaryText | Task<DialogResult> | Shows a success dialog with the supplied message and waits for the user to dismiss it. |
ShowWarningAsync | string message string title string primaryText | Task<DialogResult> | Shows a warning dialog with the supplied message and waits for the user to dismiss it. |
ShowConfirmationAsyncstring title
string primaryText
string secondaryText
message and two action buttons, then waits for the user to choose one. The returned Services.DialogResult has DialogResult.Cancelled set to ShowErrorAsyncstring title
string primaryText
message and waits for the user to dismiss it.ShowInfoAsyncstring title
string primaryText
message and waits for the user to dismiss it.ShowSuccessAsyncstring title
string primaryText
message and waits for the user to dismiss it.ShowWarningAsyncstring title
string primaryText
message and waits for the user to dismiss it.DialogResult Class
Properties
Name | Type | Default | Description |
|---|---|---|---|
Cancelled | bool | False | Gets a value indicating whether the dialog was cancelled (e.g. the user dismissed it without confirming). |
Data | Object? | Optional data payload returned by the dialog when it was closed. |
CancelledDataMethods
Name | Parameters | Type | Description |
|---|---|---|---|
Cancel | Object data | DialogResult | Creates a Services.DialogResult representing a cancelled outcome, optionally carrying a data payload. |
Ok<T> | T result | DialogResult | Creates a Services.DialogResult representing a confirmed outcome, carrying result as the data payload. |
CancelServices.DialogResult representing a cancelled outcome, optionally carrying a data payload.Ok<T>Services.DialogResult representing a confirmed outcome, carrying result as the data payload.