可以在 Blazor 布局中使用 ViewComponent 吗?

Can you use a ViewComponent in a Blazor layout?

第一次尝试 Blazor。使用默认的 Blazor 模板,我添加了一个 ViewComponent 调用 MainLayout.cshtml:

@await Component.InvokeAsync("HeaderComponent")

IntelliSense 显示 await 只能在 async 方法中使用。

我在 Blazor 视图中尝试了相同的结果——相同的结果。我在布局中的 MVC 应用程序中使用该组件(通过 <vc:header-component />)。

所以我不确定这是否可行,或者只是当前的 Blazor 或 Visual Studio 2019 限制。

不,您不能在 Blazor 中使用 ViewComponent。是的,这是一个限制,就像您不能在 Angular 中使用 ViewComponent 一样。

为什么需要局部视图? Blazor 中是否存在组件无法满足的用例?