我正在使用Mudblazor 6.10.0,我有一个对话框不显示的问题,即使我使用一个开箱即用的对话框它也打不开.我在控制台上没有收到错误,代码中也没有出现错误,但该对话框根本不会显示.单击按钮将调用ToggleOpen代码,但不显示对话框.

我的组件

@using Microsoft.AspNetCore.Components
@using MudBlazor

<MudDialog>
    <TitleContent>
        <MudText Typo="Typo.h6">
            <MudIcon Icon="@Icons.Material.Outlined.Edit" Class="mr-3 mb-n1"/>
            Changes made by @User.Name
        </MudText>
    </TitleContent>
    <DialogContent>
        <MudTextField Disabled="true"  Label="Before" @bind-Value="User.Change" Multiline="true" />
    </DialogContent>
    <DialogActions>
        <MudButton Color="Color.Primary" OnClick="Close">Ok</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] MudDialogInstance MudDialog { get; set; }
    [Parameter] 
    public UserChange User { get; set; }
   
    private void Close() => MudDialog.Close(DialogResult.Ok(true));
}

使用调用父组件

@page "/"

@using MudBlazor
@inject UserChangesService UserChangesService
@inject IDialogService DialogService

<MudText Typo="Typo.h2" Color="Color.Info">Welcome</MudText>
<MudGrid>
    <MudItem xs="12" sm="6">
        <MudCard>
            <MudCardHeader>
                <CardHeaderContent>
                    <MudText Typo="Typo.h5" Color="Color.Info">Recent changes</MudText>
                </CardHeaderContent>
                <CardHeaderActions>
                    <MudIconButton Icon="@Icons.Material.Outlined.FindInPage" Color="Color.Tertiary" />
                </CardHeaderActions>
            </MudCardHeader>
            <MudCardContent>
                @if (!_loading)
                {
                    <MudTable Striped="true" Dense="true" FixedHeader="true" Items="@_changes">
                        <HeaderContent>
                            <MudTh><strong> User </strong></MudTh>
                        </HeaderContent>
                        <RowTemplate>
                            <MudTd>@context.User</MudTd>
                            <MudTd><MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => ToggleOpen(context))">View</MudButton></MudTd>
                        </RowTemplate>
                    </MudTable>
                }
            </MudCardContent>
        </MudCard>
    </MudItem>

</MudGrid>

@code {
    private List<UserChange> _changes;
    private UserChange _selectedChange;
    private bool _loading;

    public void ToggleOpen(AuditHistory auditHistory)
    {
        var parameters = new DialogParameters<AuditChangeDialog>();
        parameters.Add(x => x.user, auditHistory);
        DialogService.Show<UserChangeDialog>("Changes", parameters);
    }
    
    protected override async Task OnInitializedAsync()
    {
        _loading = true;
        _changes = (await UserChangesService.GetAllAsync()).ToList();
        StateHasChanged();
        _loading = false;
    }
}

推荐答案

您需要按照说明在MainLayout.razor中添加<MudDialogProvider/>.https://mudblazor.com/getting-started/installation#manual-install-add-components

Csharp相关问答推荐

我无法在Program.cs中实例化我的学生类

如何禁用ASP.NET MVP按钮,以便无法使用开发人员控制台重新启用它

Monty Hall游戏节目模拟给我50/50的结果

并行令牌更新

解析需要HttpClient和字符串的服务

SignalR客户端不会打印队列位置'

静态对象构造顺序

CS1660无法将lambda表达式转换为类型INavigationBase,因为它不是委托类型

异步任务导致内存泄漏

DbContext-传递自定义配置选项

JsonSchema.Net删除假阳性判断结果

HelperText属性不支持复杂内容(混合C#和标记)

泛型参数在.NET 8 AOT中没有匹配的批注

将操作从编辑页重定向到带参数的索引页

当空判断结果赋给变量时,为什么会出现可能空异常警告的解引用?

如何避免在.NET中将日志(log)写入相对路径

JSON串行化程序问题.SQLite中的空值

为什么我在使用有效令牌的情况下仍未获授权?

实体框架允许您具有筛选的属性吗?

Excel将';@';添加到具有范围的公式中