MudBlazor 对话框未打开,没有错误

Ban*_*101 4 c# blazor blazor-server-side mudblazor

我使用的是 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));
}
Run Code Online (Sandbox Code Playgroud)

与调用父组件

@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;
    }
}
Run Code Online (Sandbox Code Playgroud)

mac*_*iek 5

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