简体   繁体   English

Radzen Blazor 对话框未关闭

[英]Radzen Blazor Dialog doesn't close

I have an issue when use dialog.Close of Radzen.Blazor.我在使用 Radzen.Blazor 的 dialog.Close 时遇到问题。 I did all step in get started of blazor.radzen我完成了 blazor.radzen 入门的所有步骤

  • Open the Shared/MainLayout.razor file and include , , and打开 Shared/MainLayout.razor 文件并包含 、 和
  • Open the Startup.cs file (server-side Blazor) or Program.cs (client-side WebAssembly Blazor) and add DialogService, NotificationService, ContextMenuService and TooltipService.打开 Startup.cs 文件(服务器端 Blazor)或 Program.cs(客户端 WebAssembly Blazor)并添加 DialogService、NotificationService、ContextMenuService 和 TooltipService。

The problem is when I open dialog, it open.问题是当我打开对话框时,它打开了。 Then I click in Button submit or Button Cancel to trigger dialog.Close(data) (Button Submit) and dialog.Close(false) (Button Cancel) it still run in function Submit/Close but it doesn't close dialog.然后我点击按钮提交或按钮取消以触发 dialog.Close(data) (Button Submit) 和 dialog.Close(false) (Button Cancel) 它仍然在函数 Submit/Close 中运行,但它不会关闭对话框。 I try to find but can see any error.我尝试查找但可以看到任何错误。

This is my code I use this to open dialog var result = await OpenAsync("Thêm mới", @Form);这是我用来打开对话框的代码var result = await OpenAsync("Thêm mới", @Form);

This is Open Async Task<dynamic> OpenAsync(string title, RenderFragment<TItem> content) => dialog.OpenAsync<WrapperForm<TItem>>(title, new Dictionary<string, object> { { "Content", content }, { "Data", null } }, FormOption ?? new DialogOptions() { Width = "700px", Top = "30px" });这是 Open Async Task<dynamic> OpenAsync(string title, RenderFragment<TItem> content) => dialog.OpenAsync<WrapperForm<TItem>>(title, new Dictionary<string, object> { { "Content", content }, { "Data", null } }, FormOption ?? new DialogOptions() { Width = "700px", Top = "30px" });

This is my WrapperForm这是我的 WrapperForm

@typeparam TItem

<div class="row">
    @Content(Data)
</div>

@code {
    [Parameter] public RenderFragment<TItem> Content { set; get; }
    [Parameter] public TItem Data { set; get; }   
}

This is component @Form i pass into OpenAsync这是我传递给 OpenAsync 的组件 @Form

@using QuanLyKiemDinh.Components

@using QuanLyKiemDinh.Helpers

@inject QuanLyKiemDinhContext dbContext
@inject Radzen.DialogService dialog

<FormBase Data="@capVanban" TItem="tbCapVanBan" Submit="@Submit" Cancel="@Cancel">
    <Items>
        <FormItem Label="Tên cấp" SM="12">
            <Item>
                <RadzenTextBox @bind-Value="@capVanban.TenCap" Placeholder="Tên cấp" Style="width: 100%" />
            </Item>
        </FormItem>
        <FormItem Label="Mô tả" SM="12">
            <Item>
                <RadzenTextBox @bind-Value="@capVanban.MoTa" Placeholder="Mô tả" Style="width: 100%" />
            </Item>
        </FormItem>
    </Items>
</FormBase>

@code {
    [Parameter] public tbCapVanBan Data { set; get; }
    tbCapVanBan capVanban = new tbCapVanBan();

    async void Submit(tbCapVanBan capVanban)
    {
        if (Data == null)
        {
            capVanban.id = SequenceId.GetInt("VBPL.Seq_tbCapVanBan");
            dbContext.tbCapVanBans.Add(capVanban);
            dbContext.SaveChanges();
        } else
        {
            dbContext.tbCapVanBans.Update(capVanban);
            dbContext.SaveChanges();
        }
        dialog.Close(capVanban);
        //dbContext.SaveChanges();
    }

    void Cancel()
    {
        dialog.Close(false);
    }

    protected override void OnInitialized()
    {
        if (Data != null)
        {
            capVanban = Data;
        }
        base.OnInitialized();
    }
}

This is my FormBase这是我的 FormBase

@typeparam TItem

@inject QuanLyKiemDinhContext dbContext
@inject Radzen.DialogService dialog
@inject NotificationService notificationService
@inject NavigationManager UriHelper

<RadzenTemplateForm TItem="TItem" Data="@Data" Style="font-family:Helvetica; width: 100%" Submit="@Submit">
    <div class="row" style="padding: 10px 20px;">
        @Items
        @if (DisableBtn != true)
        {
        <div style="padding: 10px 15px;">
            @if (Buttons == null)
            {
                <ButtonTable Text="Lưu dữ liệu" ButtonType="ButtonType.Submit" />
                <ButtonTable Text="Hủy" ButtonStyle="ButtonStyle.Light" OnClick="@Cancel"/>
                @if (MoreButtons != null)
                {
                    @MoreButtons
                }
            } else
            {
                @Buttons
            }
        </div>
        }
    </div>
</RadzenTemplateForm>

@code {
    [Parameter] public EventCallback<TItem> Submit { set; get; }
    [Parameter] public EventCallback Cancel { set; get; }
    [Parameter] public TItem Data { set; get; }
    [Parameter] public RenderFragment Items { set; get; }
    [Parameter] public RenderFragment Buttons { get; set; }
    [Parameter] public RenderFragment MoreButtons { get; set; }
    [Parameter] public Boolean? DisableBtn { set; get; }

}

I had the same problem and found out that you need to add我有同样的问题,发现你需要添加

<script async src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>

in your index.html or _Host.cshtml file.在您的 index.html 或 _Host.cshtml 文件中。

Link to the _Host.cshtml链接到_Host.cshtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM