问题
Just trying Blazor for the first time. With the default blazor template, I added a ViewComponent call to the MainLayout.cshtml:
@await Component.InvokeAsync("HeaderComponent")
Intellisense shows await can only be used in an async method.
I tried the same in a Blazor view - same result. I use the component in an MVC app in the layout (i use vc:header-component there).
So I'm not sure if this is possible, or just a current Blazor or VS2019 limitation.
回答1:
No, you can't use ViewComponent in Blazor. And yes, this is a limitation, in the same sense you can't use ViewComponent in Angular.
Why do you need a partial view ? Is there any use case in Blazor that components cannot satisfy ?
来源:https://stackoverflow.com/questions/54710764/can-you-use-a-viewcomponent-in-a-blazor-layout