要么我遗漏了某些东西,要么这个文档不够完善:https://learn.microsoft.com/en-us/aspnet/core/blazor/components/generic-type-support ?view=aspnetcore-8.0 所有示例都是关于传递数据,而我对(直接)传递组件感兴趣。
假设我有MyComponent
一个通用容器MyContainer<TComponent>
。在容器 .razor 页面中,我想写入:
@typeparam TComponent where TComponent : ComponentBase
...
<h1>This is my component</h1>
<TComponent></TComponent>
使用这样的代码我得到错误“发现具有意外名称 TComponent 的标记元素”。
备注:直接表示不使用DynamicComponent
。