c# - 将 Blazor 组件渲染为静态 HTML 并将其作为流返回
问题描述
是否可以将 blazor 组件呈现为字符串,以便我可以呈现静态 HTML。我知道将 MVC 视图呈现为字符串的方法在哪里。我需要做的是创建一种方法来创建静态 HTML 页面,该页面将下载到 WPF 应用程序,然后用户可以在浏览器中打开它?这是 MVC 应用程序的流行答案:如何将 ASP.NET MVC 视图呈现为字符串? 那么 Blazor 有类似的东西吗?我不需要在 Blazor 中执行此操作,但 web 是在 Blazor 中完成的,所以会很好。
解决方案
来自 Blazor .Net 5 RC1 https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-5-release-candidate-1/#blazor-webassembly-prerendering
在您的托管应用程序中,您可以使用组件标签助手render-mode="Static"
或render-mode="WebAssemblyPrerendered"
@page "/static-counter"
@namespace Server.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<component type="typeof(Client.Shared.MyComponent)" render-mode="WebAssemblyPrerendered" />
推荐阅读
- python - PyQt5 任务栏徽章通知
- python - 当我尝试访问屏幕 ID 时,“超级”对象没有属性“__getattr__”
- rsync - 来自指定服务器目录的 Rsync 特定列出的文件
- if-statement - 在 Power BI 中将时间格式更改为 30 分钟间隔
- c - 关于 pwd.c 文件的 SIGSEGV 分段错误?
- javascript - 如何将滚动添加到 div?
- r - 如何使用 R 编程语言在 geom_line() 中(自动)更改颜色
- sqlite - 通过命令行合并多个 Raster MBTiles(Sqlite 文件)
- ruby - 使用 ruby-install 在 Mac OSX Catalina 上安装 Ruby 2.2
- vue.js - 使用 XML2JS 从 Nuxt 中的 API 解析 XML