【问题标题】:Blazor component implemented under MVC does not get rendered在 MVC 下实现的 Blazor 组件不会被渲染
【发布时间】:2020-04-04 00:21:06
【问题描述】:

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

我错过了什么吗?

【问题讨论】:

标签: c# .net model-view-controller blazor blazor-server-side


【解决方案1】:

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

创建一个空的 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 }))

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

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 2020-03-26
    • 1970-01-01
    • 2021-02-13
    • 2022-01-16
    • 2021-07-17
    • 2020-02-21
    • 2019-01-01
    • 2020-02-15
    相关资源
    最近更新 更多