在 MVC 下实现的 Blazor 组件不会被渲染
Blazor component implemented under MVC does not get rendered
使用 .NET Core 和服务器端 Blazor 的最新版本,我在现有的 MVC 应用程序中实现了 Blazor 组件(感谢 Chris https://chrissainty.com/using-blazor-components-in-an-existing-mvc-application/) I can only render the Blazor component on the default page (i.e. https://localhost:5433). The Blazor components works totally fine in the default page but when I try to open the view using https://localhost:5433/home/index 或任何其他视图,Blazor 组件不会被渲染。
我是不是漏掉了什么?
我想通了!回答一些问题和一个可重现的例子:
创建一个空的 MVC 核心应用程序并按照 Chrissianity 的教程学习如何将 Blazor 实施到现有的 MVC https://chrissainty.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 }))
当我更改渲染模式后,页面现在可以正常工作了。
使用 .NET Core 和服务器端 Blazor 的最新版本,我在现有的 MVC 应用程序中实现了 Blazor 组件(感谢 Chris https://chrissainty.com/using-blazor-components-in-an-existing-mvc-application/) I can only render the Blazor component on the default page (i.e. https://localhost:5433). The Blazor components works totally fine in the default page but when I try to open the view using https://localhost:5433/home/index 或任何其他视图,Blazor 组件不会被渲染。
我是不是漏掉了什么?
我想通了!回答一些问题和一个可重现的例子:
创建一个空的 MVC 核心应用程序并按照 Chrissianity 的教程学习如何将 Blazor 实施到现有的 MVC https://chrissainty.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 }))
当我更改渲染模式后,页面现在可以正常工作了。