The IDialogService provides methods for displaying modal dialogs to the user, including confirmation prompts, error messages, informational notices, success notifications, and warnings.
Access the dialog service from any component. In React call useDialogService() from inside the tree wrapped by the framework dialog provider; in Blazor inject the service via property injection. Note that the PowerPortalsPro dialog service is distinct from the underlying FluentUI dialog service.
// useDialogService() returns the framework's dialog API. Available from any
// function component below the <FluentDialogProvider> mounted at the app
// root. The returned object exposes async show* methods for confirmations,
// info / success / warning / error message bars, and custom dialog rendering.
import { useDialogService } from '@powerportalspro/react-fluent';
function MyComponent() {
const dialogs = useDialogService();
// ...
}using IDialogService = PowerPortalsPro.Web.Blazor.Services.IDialogService;
[Inject]
private IDialogService _dialogService { get; set; } = null!;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.
const result = await dialogs.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
}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
}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 dialogs.showInfoAsync('The operation completed.', 'Information');
await dialogs.showSuccessAsync('Record saved successfully.', 'Success');
await dialogs.showWarningAsync('This action cannot be undone.', 'Warning');
await dialogs.showErrorAsync('An error occurred while saving.', 'Error');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");ShowDialogAsync shows content of your own, such as a form, a picker or a preview, and returns what the dialog closes with. In Blazor, pass a component (or a RenderFragment); in React, pass a function that renders the content. Set PrimaryText and SecondaryText for buttons the service draws, or leave both out for content that draws its own.
The content is given the dialog it is shown in: an IDialogContext in Blazor, received as a cascading parameter, and a DialogHandle in React, passed to the render function and available anywhere inside through useDialogHandle(). Use it to close with a value, cancel, enable or disable the primary button, or set what the primary button does. What that action returns is what the dialog returns. Return KeepOpen (KEEP_OPEN in React) to keep the dialog open, for example while the input isn't valid yet.
// The content is rendered where dialogs are hosted, not where it was opened from. It can use the app's services, but not the page's own context, so pass in what it needs.
const result = await dialogs.showDialogAsync<string>(
(dialog) => <RenameForm initialName={name} dialog={dialog} />,
{
title: 'Rename',
primaryText: 'Save',
secondaryText: 'Cancel',
},
);
if (!result.cancelled && result.data !== undefined) {
// The dialog was saved: use the name it returned
}
// RenameForm
function RenameForm({ initialName, dialog }: { initialName: string; dialog: DialogHandle<string> }) {
const [name, setName] = useState(initialName);
dialog.onPrimary(async () =>
name.trim() ? name.trim() : KEEP_OPEN); // Not valid yet: say why and keep the dialog open
return <Input value={name} onChange={(_, d) => setName(d.value)} />;
}// The content is rendered where dialogs are hosted, not where it was opened from. It can use the app's services, but not the page's own context, so pass in what it needs.
var result = await _dialogService.ShowDialogAsync<RenameDialog>(
options =>
{
options.Title = "Rename";
options.PrimaryText = "Save";
options.SecondaryText = "Cancel";
},
new Dictionary<string, object?> { [nameof(RenameDialog.InitialName)] = name });
if (result.GetData<string>() is { } newName)
{
// The dialog was saved: use the name it returned
}
// RenameDialog.razor: <FluentTextInput @bind-Value="_name" />
[CascadingParameter] public IDialogContext Dialog { get; set; } = default!;
[Parameter] public string? InitialName { get; set; }
private string? _name;
protected override void OnInitialized()
{
_name = InitialName;
Dialog.OnPrimary = () => Task.FromResult<object?>(string.IsNullOrWhiteSpace(_name)
? IDialogContext.KeepOpen // Not valid yet: say why and keep the dialog open
: _name.Trim());
}Opens a dialog with a form. Save keeps the dialog open until a name is entered, then returns it to the page; Cancel returns nothing.
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.
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.
Use the controls below to customize the dialog title and message, then click any button to see the corresponding dialog type.
Name | Type | Default | Description |
|---|---|---|---|
OpenDialogCount | int | How many dialogs this service currently has open. |
OpenDialogCountName | 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 |
ShowDialogAsync<TComponent> | Action<CustomDialogOptions> configure IDictionary<string, Object> parameters | Task<DialogResult> | Shows |
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. |
ShowConfirmationAsyncmessage and two action buttons, then waits for the user to choose one. The returned Services.DialogResult has DialogResult.Cancelled set to ShowDialogAsync<TComponent>ShowErrorAsyncmessage and waits for the user to dismiss it.ShowInfoAsyncmessage and waits for the user to dismiss it.ShowSuccessAsyncmessage and waits for the user to dismiss it.ShowWarningAsyncmessage and waits for the user to dismiss it.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. |
CancelledDataName | Parameters | Type | Description |
|---|---|---|---|
Cancel | Object data | DialogResult | Creates a Services.DialogResult representing a cancelled outcome, optionally carrying a data payload. |
GetData<T> | T? | The value the dialog closed with, as | |
Ok<T> | T result | DialogResult | Creates a Services.DialogResult representing a confirmed outcome, carrying result as the data payload. |
TryGetData<T> | out T value | bool | Reads the value the dialog closed with, as |
CancelServices.DialogResult representing a cancelled outcome, optionally carrying a data payload.GetData<T>Ok<T>Services.DialogResult representing a confirmed outcome, carrying result as the data payload.TryGetData<T>Name | Type | Default | Description |
|---|---|---|---|
PreventDismissOnEscape | bool | False | Whether Escape is kept from closing the dialog. Default false. |
PrimaryText | string? | The primary button's label. The service draws the button when this is set; leave both this and CustomDialogOptions.SecondaryText unset for content that draws its own buttons. What the button does is up to IDialogContext.OnPrimary. | |
SecondaryText | string? | The secondary button's label. The service draws the button when this is set, and it cancels the dialog. | |
ShowDismiss | bool | True | Whether the header shows a close button. Default true. |
Title | string? | The dialog's title, shown in its header. Omit it for a dialog without one. | |
Width | string? | The dialog's width as a CSS length, e.g. |
PreventDismissOnEscapefalse.PrimaryTextCustomDialogOptions.SecondaryText unset for content that draws its own buttons. What the button does is up to IDialogContext.OnPrimary.SecondaryTextShowDismisstrue.TitleWidthName | Type | Default | Description |
|---|---|---|---|
OnPrimary | Func<Task<Object>>? | Runs when the service-drawn primary button is pressed. Its result is what the dialog returns, in DialogResult.Data; return IDialogContext.KeepOpen to keep the dialog open instead. Unset, the button closes the dialog with no data. While it runs the buttons are disabled and Escape doesn't dismiss the dialog (on Blazor Server, from a moment after the click: the block reaches the browser a round trip later). If it throws, the error is logged, the dialog stays open, and a general error message is shown over it; for failures a user can fix, say what went wrong yourself and return IDialogContext.KeepOpen. | |
PrimaryEnabled | bool | Whether the service-drawn primary button can be pressed, e.g. only once a required choice is made. Default true. |
OnPrimaryDialogResult.Data; return IDialogContext.KeepOpen to keep the dialog open instead. Unset, the button closes the dialog with no data. While it runs the buttons are disabled and Escape doesn't dismiss the dialog (on Blazor Server, from a moment after the click: the block reaches the browser a round trip later). If it throws, the error is logged, the dialog stays open, and a general error message is shown over it; for failures a user can fix, say what went wrong yourself and return IDialogContext.KeepOpen.PrimaryEnabledtrue.Name | Parameters | Type | Description |
|---|---|---|---|
CancelAsync | Task | Closes the dialog as cancelled, which returns Cancel(System.Object). | |
CloseAsync | Object data | Task | Closes the dialog, which returns DialogResult.Ok`<T>(`<U>) with data. |
CancelAsyncCancel(System.Object).CloseAsyncDialogResult.Ok`<T>(`<U>) with data.