Radzen Blazor 对话框未关闭
Radzen Blazor Dialog doesn't close
我在使用 dialog.Close 或 Radzen.Blazor 时遇到问题。我完成了 blazor.radzen
入门的所有步骤
- 打开 Shared/MainLayout.razor 文件并包含 、 和
- 打开 Startup.cs 文件(服务器端 Blazor)或 Program.cs(客户端 WebAssembly Blazor)并添加 DialogService、NotificationService、ContextMenuService 和 TooltipService。
问题是当我打开对话框时,它打开了。然后我单击按钮提交或按钮取消以触发 dialog.Close(data)(按钮提交)和 dialog.Close(false)(按钮取消)它仍然 运行 在功能 Submit/Close但它不会关闭对话框。
我试图找到但可以看到任何错误。
这是我的代码
我用它来打开对话框 var result = await OpenAsync("Thêm mới", @Form);
这是开放异步
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" });
这是我的 WrapperForm
@typeparam TItem
<div class="row">
@Content(Data)
</div>
@code {
[Parameter] public RenderFragment<TItem> Content { set; get; }
[Parameter] public TItem Data { set; get; }
}
这是我传入 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();
}
}
这是我的 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; }
}
我遇到了同样的问题,发现你需要添加
<script async src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
在您的 index.html 或 _Host.cshtml 文件中。
Link 到 _Host.cshtml
我在使用 dialog.Close 或 Radzen.Blazor 时遇到问题。我完成了 blazor.radzen
入门的所有步骤- 打开 Shared/MainLayout.razor 文件并包含 、 和
- 打开 Startup.cs 文件(服务器端 Blazor)或 Program.cs(客户端 WebAssembly Blazor)并添加 DialogService、NotificationService、ContextMenuService 和 TooltipService。
问题是当我打开对话框时,它打开了。然后我单击按钮提交或按钮取消以触发 dialog.Close(data)(按钮提交)和 dialog.Close(false)(按钮取消)它仍然 运行 在功能 Submit/Close但它不会关闭对话框。 我试图找到但可以看到任何错误。
这是我的代码
我用它来打开对话框 var result = await OpenAsync("Thêm mới", @Form);
这是开放异步
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" });
这是我的 WrapperForm
@typeparam TItem
<div class="row">
@Content(Data)
</div>
@code {
[Parameter] public RenderFragment<TItem> Content { set; get; }
[Parameter] public TItem Data { set; get; }
}
这是我传入 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();
}
}
这是我的 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; }
}
我遇到了同样的问题,发现你需要添加
<script async src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
在您的 index.html 或 _Host.cshtml 文件中。
Link 到 _Host.cshtml