Skip to content

DialogService.OpenAsync should accept Dictionary<string, object?>? parameters #2448

@DashNY

Description

@DashNY

Describe the bug

The signature of this method is currently

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

It should be

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

The subtle difference here is that the dictionary's value can be a null, and therefore should be defined as object? rather than just object.

Consider this code:

    private async Task ShowDetailsPopup(PersonDto? person)
    {
        PopupClosedArgs<PersonDto>? result = await DialogService.OpenAsync<PersonDetailsPopup>($"Edit Person",
            new Dictionary<string, object?>() { { "id", person?.Id } },
            new DialogOptions
            {
                Resizable = true,
                Draggable = true,
                Width = "700px",
                Height = "512px",
            });

        if (result?.Action == PopupClosedAction.Ok)
        {
            var actionCompleted = person is null ? "created" : "updated";
            NotificationService.Notify(NotificationSeverity.Info, $"Person {result.Data!.Name} {actionCompleted}");
        }
    }

Expected behavior
The compiler shouldn't give you any warnings like it does right now:

Argument of type 'System.Collections.Generic.Dictionary<string,object?>' cannot be used for parameter 'parameters' of type 'System.Collections.Generic.Dictionary<string,object>?' in 'Radzen.DialogService.OpenAsync<T>' because of differences in the nullability of reference types

Note that it's completely acceptable for the passed in parameter to be nullable inside the popup component. E..g. it would be defined there as follows

@code {
    [Parameter] public string? Id { get; set; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions