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();
}
}
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;
}