Dialog Close Error

Hello,

When I try to close the dialog from 'X' , I get this error.

Error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot convert null to 'bool' because it is a non-nullable value type

   at CallSite.Target(Closure , CallSite , Object )

   at IMS.WebApp.Pages.Orders.OrderList.ShowInlineDialog(OrderDetail orderDetail) in C:\Users\197199\Source\Repos\IMS.WebApp\IMS.WebApp\Pages\Orders\OrderList.razor:line 602

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Radzen.Blazor.RadzenButton.OnClick(MouseEventArgs args)

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState) bl

Here is the screenshot:

Here is the code:

async Task ShowInlineDialog(OrderDetail orderDetail)
    {
        var result = await DialogService.OpenAsync("Delete Order Detail", ds =>
            @<div>
                <p class="mb-4">Do you want to delete Product ID <b>@orderDetail.Id</b>, Product Code: <b>@orderDetail.ProductCode</b> ?</p>
                <div class="row">
                    <div class="col">
                        <RadzenButton Text="Ok" Click="() => ds.Close(true)" Class="mr-1" Style="width: 80px;"/>
                        <RadzenButton Text="Cancel" Click="() => ds.Close(false)" ButtonStyle="ButtonStyle.Light" Class="mr-1"/>

                    </div>
                </div>
            </div>
            );

        if (result)
        {
            await DeleteDetail(orderDetail);
        }
        else
        {
            CancelEditDetail(orderDetail);
        }
    }

Thank you.

The DialogService returns null if you use the close button. You can use the built-in Confirm method instead:

var result = await DialogService.Confirm("Are you sure?", "MyTitle", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" })
1 Like

Thank you, I check for the null condition.