无法在 Razor 页面上使用 <component /> 标签助手?

Can't use the <component /> tag helper on a Razor Page?

我正在使用 DotNetCore 3.1 和 Razor Pages。

我想使用我在 Index.Razor 页面上创建的 Razor 组件,但让它使用 'Static' 渲染模式。

根据文档:

To render a component from a page or view, use the Component Tag Helper:

<component type="typeof(Counter)" render-mode="ServerPrerendered" 
    param-IncrementAmount="10" />

正如您在下面看到的,我可以使用它的名称作为标记 (<Lister></Lister>) 来呈现我的组件(名为 Lister)。但是,我无法使用 <component /> 标签助手来呈现它。

如果我 运行 页面,它既不会将语法突出显示为可识别的标记助手,也不会实际呈现它。

当我执行 运行 页面时,它不显示组件,而是显示为

<component type="typeof(Lister)" render-mode="Static"></component>

在页面源中。

在另一个项目中,我能够在 MVC 视图 (.cshtml) 文件中呈现相同的组件(使用相同的语法)。


编辑:

好的,所以我认为我 missed/messed 的是我的 Index.razor 文件不是 Razor 页面,而是一个可路由的 Razor 组件。

我错误地将 Blazor 项目当成了 Razor Pages 项目。

Razor Pages 有 .cshtml 种文件类型

Razor 组件具有 .razor 文件类型(并且可能具有令人困惑的 @page 指令)

Razor 组件无法访问 <component /> 标签助手,必须通过 <theNameOfIt></theNameOfIt>

使用其他 Razor 组件

感谢您的帮助!

组件 Tag Helper 不是 Blazor 对象。 Blazor 中不存在标签助手或 html 助手的概念。这是 Razor Pages 和 MVC 的领域。在 Blazor 中,我们有一个组件模型。

通常您应该使用 _Host.cshtml 文件中的组件 Tag Helper 来呈现 Razor App 组件。

您不能在 Index.razor 组件中嵌入组件 Tag Helper。您不能在 Blazor 中使用组件 Tag Helper。 _Host.cshtml 文件不是 Blazor。它是启动 Blazor 应用程序的 Razor Pages 文件...