Radzen Dialog Service How to Return Data on Close?

Hi,

I want to return a string from Radzen Dialog but can't manage it yet. Any help would be great.

private async Task ChangeDoneBy(object args)
{
    orders = (OrderDto)args;
   var result = await DialogService.OpenAsync<DialogCardChangeDoneBy>("",
        new Dictionary<string, object>() { { "Order", orders } },
        new DialogOptions() { Width = "650px", Height = "600px", Resizable = true, Draggable = true, ShowClose = false, CloseDialogOnEsc = true });

   if (result == null)
   {
       // CancelEditDetail(orderDetail);
   }
   else if (result)
   {
       // await DeleteDetail(orderDetail);
   }
   else
   {
       // CancelEditDetail(orderDetail);
   }
}
@page "/dialogcardchangedoneby/{Order}"
@using IMS.CoreBusiness
@using IMS.CoreBusiness.DTO
@using Microsoft.AspNetCore.Identity
@inject DialogService DialogService

    <RadzenCard >
        <div>
            <table class="table">
                <thead>
                <tr>

                    <th>Users</th>

                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach (var user in users)
                {
                    <tr>

                        <td>@user.UserName</td>

                        <td>
                            <button @onclick="() => SelectUser(user.Id)">Select User</button>
                        </td>
                    </tr>
                }
                </tbody>
            </table>
        </div>
        <hr/>
        <div>
            <div>
                @selectedUser
            </div>

        </div>
    </RadzenCard>
    <div class="row" style="margin-top: 20px;">
        <div class="col-md-12 text-right">
            <RadzenButton Click="@((args) => DialogService.Close(selectedUser))" Text="Update" Style="width: 120px" Disabled="string.IsNullOrEmpty(selectedUser)"/>
            <RadzenButton Click="@((args) => DialogService.Close(false))" ButtonStyle="ButtonStyle.Secondary" Text="Close" Style="width: 120px" Class="mr-1"/>

        </div>
    </div>

@code {
    [Parameter] public OrderDto Order { get; set; }
    [Inject]
    public RoleManager<IdentityRole> roleManager { get; set; }
    [Inject]
    public UserManager<IdentityUser> userManager { get; set; }

    private List<IdentityRole> roles = new List<IdentityRole>();
    private List<IdentityUser> users = new List<IdentityUser>();
    private string selectedUser { get; set; } = "";
    private string userRole { get; set; }

    protected override async Task OnInitializedAsync()
    {
        roles = roleManager.Roles.ToList();
        users = userManager.Users.ToList();
    }

    private async Task SelectUser(string id)
    {
        var user = await userManager.FindByIdAsync(id);
        selectedUser = user.UserName;
        userRole = (await userManager.GetRolesAsync(user)).FirstOrDefault() ?? "";
    }

   
}

Check the Close() methods in DialogCardPage in our first example:

1 Like

Close methods do not return string values, how can I return a string in my case?

The argument is dynamic, you can return anything: