C# LayerHost不存在Blazor Fluent UI下拉列表问题
我正在进行我的第一个Blazor客户端项目,我正在使用Blazor Fluent UI包进行组件开发。目前,我正在页面中添加下拉组件,但当我运行项目并单击下拉组件时,出现错误: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:LayerHost不存在。您需要在应用程序根目录附近添加一个LayerHost。 系统异常:LayerHost不存在。您需要添加一个 LayerHost靠近应用程序的根目录。在 BlazorFluentUI.BFULayer.OnParametersSetAsync()位于 Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync() 在 Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() 我正在基于以下代码示例创建下拉组件:C# LayerHost不存在Blazor Fluent UI下拉列表问题,c#,blazor-client-side,C#,Blazor Client Side,我正在进行我的第一个Blazor客户端项目,我正在使用Blazor Fluent UI包进行组件开发。目前,我正在页面中添加下拉组件,但当我运行项目并单击下拉组件时,出现错误: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:LayerHost不存在。您需要在应用程序根目录附近添加一个LayerHost。 系统异常:LayerHost不存在。您需要添加一个 Laye
<BFUDropdown ItemsSource=@items
Placeholder="Select an option"
OnChange=@UncontrolledSingleChangeHandler
Label=@($"Selected: {uncontrolledSingleSelectionResult?.Text}")
Style="width:300px;" />
@code {
IBFUDropdownOption uncontrolledSingleSelectionResult;
IEnumerable<IBFUDropdownOption> uncontrolledMultiSelectionResult = new List<IBFUDropdownOption>();
IBFUDropdownOption controlledSingleSelectionResult;
IEnumerable<IBFUDropdownOption> controlledMultiSelectionResult;
List<IBFUDropdownOption> items;
protected override Task OnInitializedAsync()
{
items = new List<DataItem> {
new DataItem("Fruits", SelectableOptionMenuItemType.Header),
new DataItem("Apple"),
new DataItem("Banana"),
new DataItem("Orange"),
new DataItem("Grape"),
new DataItem("divider1", SelectableOptionMenuItemType.Divider),
new DataItem("Vegetables", SelectableOptionMenuItemType.Header),
new DataItem("Broccoli"),
new DataItem("Carrot"),
new DataItem("Lettuce")
}.Select(x => new BFUDropdownOption { Key = x.Key, Text = x.DisplayName, ItemType = x.Type }).Cast<IBFUDropdownOption>().ToList();
controlledSingleSelectionResult = items.First(x => x.Key == "Banana");
controlledMultiSelectionResult = items.Where(x => x.Key == "Banana" || x.Key == "Orange");
return base.OnInitializedAsync();
}
void UncontrolledSingleChangeHandler(BFUDropdownChangeArgs args)
{
uncontrolledSingleSelectionResult = args.Option;
}
void UncontrolledMultiChangeHandler(BFUDropdownChangeArgs args)
{
if (args.IsAdded)
uncontrolledMultiSelectionResult = uncontrolledMultiSelectionResult.Append(args.Option);
else
uncontrolledMultiSelectionResult = uncontrolledMultiSelectionResult.Where(x=> x != args.Option);
}
ExampleModel exampleModel = new ExampleModel();
class ExampleModel
{
[Required]
public IBFUDropdownOption SelectionResult { get; set; }
}
public void HandleValidSubmit()
{
var i = 3;
}
}
@代码{
IBFUDROPDOWN选项不受控制的SingleSelectionResult;
IEnumerable uncontrolledMultiSelectionResult=新列表();
IBFUDropdownOption控制的SingleSelectionResult;
i可数可控多选结果;
清单项目;
受保护的覆盖任务OnInitializedAsync()
{
项目=新列表{
新数据项(“水果”,SelectableOptionMenuItemType.Header),
新数据项(“苹果”),
新数据项(“香蕉”),
新数据项(“橙色”),
新数据项(“葡萄”),
新数据项(“divider1”,SelectableOptionMenuItemType.Divider),
新数据项(“蔬菜”,SelectableOptionMenuItemType.Header),
新数据项(“西兰花”),
新数据项(“胡萝卜”),
新数据项(“莴苣”)
}.Select(x=>newbfudropdownpoption{Key=x.Key,Text=x.DisplayName,ItemType=x.Type}).Cast().ToList();
controlledSingleSelectionResult=items.First(x=>x.Key==“香蕉”);
Controlled MultiSelectionResult=项目。其中(x=>x.Key==“香蕉”| | x.Key==“橙色”);
返回base.OnInitializedAsync();
}
void UncontrolledSingleChangeHandler(BFUDropdownChangeArgs args args)
{
不受控制的SingleSelectionResult=args.Option;
}
无效不受控制的MultiChangeHandler(BFUDropdownChangeArgs args args)
{
如果(参数已添加)
uncontrolledMultiSelectionResult=uncontrolledMultiSelectionResult.Append(args.Option);
其他的
uncontrolledMultiSelectionResult=uncontrolledMultiSelectionResult.Where(x=>x!=args.Option);
}
ExampleModel ExampleModel=新ExampleModel();
类示例模型
{
[必需]
public ibfudropdown选项SelectionResult{get;set;}
}
公共无效手册提交()
{
var i=3;
}
}
示例的链接是:
我在App.razor页面中找到了LayerHost组件,但即使添加了它,我也会得到相同的异常
这是我的App.razor页面的代码:
<BFUTheme>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<BFULayerHost>
</BFULayerHost>
</CascadingAuthenticationState>
</BFUTheme>
@如果(!context.User.Identity.IsAuthenticated)
{
}
其他的
{
您无权访问此资源
}
对不起,这个地址什么也没有
我如何告诉下拉组件使用bFulayHost?也有同样的问题,请通过将
<BFULayerHost>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
...
</Router>
</BFULayerHost>
...
谢谢。它现在正在工作。