首页 > 解决方案 > 在 MVC 下实现的 Blazor 组件未呈现

问题描述

使用 .NET Core 和最新版本的服务器端 Blazor,我在现有 MVC 应用程序中实现了 Blazor 组件(感谢 Chris https://chrissinty.com/using-blazor-components-in-an-existing-mvc-application / ) 我只能在默认页面(即https://localhost:5433)上呈现 Blazor 组件。Blazor 组件在默认页面中运行良好,但是当我尝试使用https://localhost:5433/home/index或任何其他视图打开视图时,Blazor 组件不会被呈现。

我在这里错过了什么吗?

标签: c#.netmodel-view-controllerblazorblazor-server-side

解决方案


我想到了!回答一些问题和一个可重复的例子:

创建一个空的 MVC 核心应用程序并按照 Chrissianity 的教程了解如何将 Blazor 实施到现有 MVC https://chrissinty.com/using-blazor-components-in-an-existing-mvc-application/

我没有注意到我正在使用

@(await Html.RenderComponentAsync<CoursesList>(**RenderMode.Server**, 
     new { Courses = Model }))

而不是

@(await Html.RenderComponentAsync<CoursesList(**RenderMode.ServerPrerendered**, 
   new { Courses = Model }))

当我更改渲染模式时,页面现在可以工作了。


推荐阅读