问题描述
只是第一次尝试Blazor.使用默认的Blazor模板,我在MainLayout.cshtml
中添加了ViewComponent
调用:
Just trying Blazor out for the first time. With the default Blazor template, I added a ViewComponent
call to the MainLayout.cshtml
:
@await Component.InvokeAsync("HeaderComponent")
IntelliSense显示await
只能在async
方法中使用.
IntelliSense shows await
can only be used in an async
method.
我在Blazor视图中尝试了相同的结果.我在布局中的MVC应用程序中使用了该组件(通过<vc:header-component />
).
I tried the same in a Blazor view—same result. I use the component in an MVC app in the layout (via <vc:header-component />
).
所以我不确定这是否可行,或者不确定当前的Blazor或Visual Studio 2019限制.
So I'm not sure if this is possible, or just a current Blazor or Visual Studio 2019 limitation.
推荐答案
否,您不能在Blazor中使用ViewComponent.是的,这是一个限制,从某种意义上讲,您不能在Angular中使用ViewComponent.
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.
为什么需要局部视图? Blazor中有组件无法满足的用例吗?
Why do you need a partial view ? Is there any use case in Blazor that components cannot satisfy ?
这篇关于可以在Blazor布局中使用ViewComponent吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!