Table of Contents

Class DialogService

Namespace
Radzen
Assembly
Radzen.Blazor.dll

Class DialogService. Contains various methods with options to open and close dialogs. Should be added as scoped service in the application services and RadzenDialog should be added in application main layout.

public class DialogService : IDisposable
Inheritance
DialogService
Implements
Inherited Members

Examples

@inject DialogService DialogService
<RadzenButton Text="Show dialog with inline Blazor content" Click=@ShowInlineDialog />
@code {
 async Task ShowInlineDialog()
 {
   var result = await DialogService.OpenAsync("Simple Dialog", ds =>
     @<div>
         <p Style="margin-bottom: 1rem">Confirm?</p>
         <div class="row">
             <div class="col-md-12">
                 <RadzenButton Text="Ok" Click="() => ds.Close(true)" Style="margin-bottom: 10px; width: 150px" />
                 <RadzenButton Text="Cancel" Click="() => ds.Close(false)" ButtonStyle="ButtonStyle.Base"  Style="margin-bottom: 10px; width: 150px"/>
                 <RadzenButton Text="Refresh" Click="(() => { orderID = 10249; ds.Refresh(); })" ButtonStyle="ButtonStyle.Info"  Style="margin-bottom: 10px; width: 150px"/>
                 Order ID: @orderID
             </div>
         </div>
     </div>);
   Console.WriteLine($"Dialog result: {result}");
 }
}

Constructors

DialogService(NavigationManager, IJSRuntime)

Initializes a new instance of the DialogService class.

public DialogService(NavigationManager uriHelper, IJSRuntime jsRuntime)

Parameters

uriHelper NavigationManager

The URI helper.

jsRuntime IJSRuntime

IJSRuntime instance.

Fields

dialogs

The dialogs

protected List<object> dialogs

Field Value

List<object>

tasks

The tasks

protected List<TaskCompletionSource<dynamic>> tasks

Field Value

List<TaskCompletionSource<dynamic>>

Methods

Alert(string, string, AlertOptions)

Displays a alert dialog.

public virtual Task<bool?> Alert(string message = "", string title = "Message", AlertOptions options = null)

Parameters

message string

The message displayed to the user.

title string

The text displayed in the title bar of the dialog.

options AlertOptions

The options.

Returns

Task<bool?>

true if the user clicked the OK button, false otherwise.

Close(dynamic)

Closes the last opened dialog with optional result.

[JSInvokable("DialogService.Close")]
public virtual void Close(dynamic result = null)

Parameters

result dynamic

The result.

CloseSide(dynamic)

Closes the side dialog

public void CloseSide(dynamic result = null)

Parameters

result dynamic

The result of the Dialog

Confirm(string, string, ConfirmOptions)

Displays a confirmation dialog.

public virtual Task<bool?> Confirm(string message = "Confirm?", string title = "Confirm", ConfirmOptions options = null)

Parameters

message string

The message displayed to the user.

title string

The text displayed in the title bar of the dialog.

options ConfirmOptions

The options.

Returns

Task<bool?>

true if the user clicked the OK button, false otherwise.

Dispose()

public void Dispose()

Open(string, RenderFragment<DialogService>, DialogOptions)

Opens a dialog with the specified content.

public virtual void Open(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)

Parameters

title string

The text displayed in the title bar of the dialog.

childContent RenderFragment<DialogService>

The content displayed in the dialog.

options DialogOptions

The dialog options.

OpenAsync(RenderFragment<DialogService>, RenderFragment<DialogService>, DialogOptions)

Opens a dialog with the specified content.

public virtual Task<dynamic> OpenAsync(RenderFragment<DialogService> titleContent, RenderFragment<DialogService> childContent, DialogOptions options = null)

Parameters

titleContent RenderFragment<DialogService>

The content displayed in the title bar of the dialog.

childContent RenderFragment<DialogService>

The content displayed in the dialog.

options DialogOptions

The dialog options.

Returns

Task<dynamic>

The value passed as argument to Close(dynamic).

OpenAsync(string, RenderFragment<DialogService>, DialogOptions)

Opens a dialog with the specified content.

public virtual Task<dynamic> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)

Parameters

title string

The text displayed in the title bar of the dialog.

childContent RenderFragment<DialogService>

The content displayed in the dialog.

options DialogOptions

The dialog options.

Returns

Task<dynamic>

The value passed as argument to Close(dynamic).

OpenAsync<T>(string, Dictionary<string, object>, DialogOptions)

Opens a dialog with the specified arguments.

public virtual Task<dynamic> OpenAsync<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase

Parameters

title string

The text displayed in the title bar of the dialog.

parameters Dictionary<string, object>

The dialog parameters. Passed as property values of T.

options DialogOptions

The dialog options.

Returns

Task<dynamic>

The value passed as argument to Close(dynamic).

Type Parameters

T

The type of the Blazor component which will be displayed in a dialog.

OpenSideAsync<T>(string, Dictionary<string, object>, SideDialogOptions)

Opens a side dialog with the specified arguments

public Task<dynamic> OpenSideAsync<T>(string title, Dictionary<string, object> parameters = null, SideDialogOptions options = null) where T : ComponentBase

Parameters

title string

The text displayed in the title bar of the side dialog.

parameters Dictionary<string, object>

The dialog parameters. Passed as property values of T

options SideDialogOptions

The side dialog options.

Returns

Task<dynamic>

A task that completes when the dialog is closed or a new one opened

Type Parameters

T

The type of Blazor component which will be displayed in the side dialog.

Open<T>(string, Dictionary<string, object>, DialogOptions)

Opens a dialog with the specified arguments.

public virtual void Open<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase

Parameters

title string

The text displayed in the title bar of the dialog.

parameters Dictionary<string, object>

The dialog parameters. Passed as property values of T.

options DialogOptions

The dialog options.

Type Parameters

T

The type of the Blazor component which will be displayed in a dialog.

Refresh()

Invokes OnRefresh.

public void Refresh()

Events

OnClose

Raises the Close event.

public event Action<dynamic> OnClose

Event Type

Action<dynamic>

OnOpen

Occurs when a new dialog is open.

public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen

Event Type

Action<string, Type, Dictionary<string, object>, DialogOptions>

OnRefresh

Occurs when [on refresh].

public event Action OnRefresh

Event Type

Action

OnSideClose

Raises the Close event for the side dialog

public event Action<dynamic> OnSideClose

Event Type

Action<dynamic>

OnSideOpen

Raises the Open event for the side dialog

public event Action<Type, Dictionary<string, object>, SideDialogOptions> OnSideOpen

Event Type

Action<Type, Dictionary<string, object>, SideDialogOptions>