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.
IDialogService
Here is an example that demonstrates the use of a IDialogService component.
IDialogService Class
Methods
Name | Parameters | Type | Description |
|---|---|---|---|
ShowConfirmationAsync | string message string title string primaryText string secondaryText | Task<DialogResult> | Shows a confirmation dialog with the supplied and two action buttons, then waits for the user to choose one. The returned has set to true when the user selects the secondary (negative) option. |
ShowErrorAsync | string message string title string primaryText | Task<DialogResult> | Shows an error dialog with the supplied and waits for the user to dismiss it. |
ShowInfoAsync | string message string title string primaryText | Task<DialogResult> | Shows an informational dialog with the supplied and waits for the user to dismiss it. |
ShowSuccessAsync | string message string title string primaryText | Task<DialogResult> | Shows a success dialog with the supplied and waits for the user to dismiss it. |
ShowWarningAsync | string message string title string primaryText | Task<DialogResult> | Shows a warning dialog with the supplied and waits for the user to dismiss it. |
ShowConfirmationAsyncstring title
string primaryText
string secondaryText
the user to choose one. The returned has set to
true when the user selects the secondary (negative) option.
ShowErrorAsyncstring title
string primaryText
ShowInfoAsyncstring title
string primaryText
ShowSuccessAsyncstring title
string primaryText
ShowWarningAsyncstring title
string primaryText
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). |
CancelledMethods
Name | Parameters | Type | Description |
|---|---|---|---|
Cancel | Object data | DialogResult | Creates a representing a cancelled outcome, optionally carrying a data payload. |
Ok<T> | T result | DialogResult | Creates a representing a confirmed outcome, carrying as the data payload. |
CancelOk<T>