Unable To Close Dialogue Manually With Value

Hi all. New here and just started using the Radzen Components which are awesome. I am trying to open a Dialogue from a button, select an item and pass that back to the page that opened the Dialogue. It all works fine, apart from when I call the DialogService.Close() method, nothing happens

This is the method that opens the Dialogue

    private async Task AddProperty()
    {
        var result = await DialogService.OpenSideAsync<ListContentTypeProperties>("Add Property",
            new Dictionary<string, object> { { "Id", ContentType.Id } },
            new SideDialogOptions { CloseDialogOnOverlayClick = true, Position = DialogPosition.Right, ShowMask = true });
        if (!string.IsNullOrEmpty(result))
        {
            var selectedProperty = result;
            StateHasChanged();
        }
    }

And this is my ListContentTypeProperties component

<RadzenListBox FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" 
               FilterOperator="StringFilterOperator.StartsWith" 
               AllowFiltering="true"
               @bind-Value="@SelectedProperty" 
               Data="@Properties" 
               TextProperty="Name" 
               ValueProperty="Alias" 
               Style="width: 100%; height: 100%;"
               InputAttributes="@(new Dictionary<string, object> { { "aria-label", "select property" } })"
               Change="@OnPropertySelected">
    <Template>
        @((context as IContentProperty)?.Name)
    </Template>
</RadzenListBox>

@code {
    [Inject] public ExtensionManager ExtensionManager { get; set; } = default!;
    [Inject] public DialogService DialogService { get; set; } = default!;

    [Parameter] public Guid Id { get; set; }

    public IEnumerable<IContentProperty> Properties { get; set; } = Enumerable.Empty<IContentProperty>();
    public string SelectedProperty { get; set; } = string.Empty;

    private Dictionary<string, IContentProperty> AllContentProperties { get; set; } = new();

    protected override void OnInitialized()
    {
        AllContentProperties = ExtensionManager.GetInstances<IContentProperty>(true);
        Properties = AllContentProperties.Select(x => x.Value);
        base.OnInitialized();
    }

    private async Task OnPropertySelected()
    {
        if (!string.IsNullOrEmpty(SelectedProperty))
        {
            Console.WriteLine($"Attempting to close dialog with selected property: {SelectedProperty}");
            await InvokeAsync(() => {
                DialogService.Close(SelectedProperty);
            });
        }
        else
        {
            Console.WriteLine("No property selected or SelectedProperty is empty");
        }
    }
}

I presume I need to get reference to the current instance of the Dialogue this component is being opened in? And call close on that?

Anyway. I'm a bit stuck, any help greatly appreciated. As above, it gets the the close line but nothing happens.

Hi @YodasMyDad,

Try the CloseSide method. It should be used for closing side dialogs:

DialogService.CloseSide()
1 Like

:man_facepalming: Thank you. That is now all working perfectly.