79492834

Date: 2025-03-07 16:00:57
Score: 0.5
Natty:
Report link

I can answer my own question: It is important to use DialogContent instead of MudDialogContent, as well as TitleContent and DialogActions without the Mud prefix. Here is the corrected LoginDialog.razor file:

@inject IDialogService DialogService
@using MyNamespace.UserRepo;
@using Microsoft.AspNetCore.Components
@using MudBlazor

<MudDialogProvider />

<MudDialog>
    <TitleContent>
        Login
    </TitleContent>
    <DialogContent>
        <MudTextField @bind-Value="_username" Label="Username" Required="true" Adornment="Adornment.Start" AdornmentIcon="mdi-account" />
        <MudTextField @bind-Value="_password" Label="Password" Required="true" Password="true" Adornment="Adornment.Start" AdornmentIcon="mdi-lock" />
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="PerformLogin">Log in</MudButton>
        <MudButton OnClick="CancelDialog">Cancel</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter]
    private IMudDialogInstance MudDialog { get; set; }
    private string _username = "";
    private string _password = "";

    private void CloseDialog()
    {
        MudDialog.Close(DialogResult.Ok(true));
    }

    private void CancelDialog()
    {
        MudDialog.Cancel();
    }

    internal async Task PerformLogin()
    {
        UserRepo.Models.User? loggedInUser = await UserRepo.Loader.LoadUsers(_username, _password);
        CloseDialog();
    }
}

This is a simple dialog as I expected it.

In MainLayout.razor:

at the top of the page: @inject IDialogService DialogService

private async void ShowLoginDialog(MouseEventArgs args)
{
    MudBlazor.IDialogReference? dialog = await DialogService.ShowAsync<LoginDialog>("");
    DialogResult? result = await dialog.Result;
}
Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Daniel