我正在尝试动态创建 MudMenu,反序列化 json 并构建菜单层次结构,如下所示。 菜单正在显示,但是单击菜单并没有打开子菜单...
<MudLayout>
<MudAppBar Elevation="1">
<MudMenu FullWidth="true">
<ActivatorContent>
<MudAvatar Size="Size.Large">
<MudImage class="myImage" Src="/Images/paradise_logo.png" Elevation="25"/>
</MudAvatar>
</ActivatorContent>
</MudMenu>
@if(categories != null)
{
@foreach (var category in categories.AllCategories.Values)
{
<MudMenu StartIcon="@Icons.Material.Rounded.Grain" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@category.CategoryName" Color="Color.Primary" Variant="Variant.Filled">
<ChildContent>
@foreach(var subCategory in category.SubCategories) {
<MudMenuItem>"@subCategory.Value.CategoryName"</MudMenuItem>
}
</ChildContent>
</MudMenu>
}
}
<MudSpacer />
<MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />
</MudAppBar>
<MudMainContent>
@Body
</MudMainContent>
</MudLayout>
如果您在每个页面/组件中使用 InterActiveServer,它将无法工作。您需要将
App.razor
更改为全局交互服务器模式。
<Routes @rendermode="InteractiveServer" />