简体   繁体   English

将 Blazor 组件渲染为静态 HTML 并将其作为流返回

[英]Render Blazor component to static HTML and return it as stream

Is it possible to render blazor component as string so I can render static HTML.是否可以将 blazor 组件呈现为字符串,以便我可以呈现静态 HTML。 I know where is a way to render MVC view to string.我知道在哪里可以将 MVC 视图呈现为字符串。 What I need to do is to make a way to create static HTML page that will be downloaded to WPF application where user can then open it in browser?我需要做的是设法创建静态 HTML 页面,该页面将下载到 WPF 应用程序,然后用户可以在浏览器中打开它? This is popular answer for MVC app: How to render an ASP.NET MVC view as a string?这是 MVC 应用程序的流行答案: How to render an ASP.NET MVC view as a string? So is there anything similar for Blazor?那么 Blazor 有类似的东西吗? I don't need to do it in Blazor but web is done in Blazor so it would be nice.我不需要在 Blazor 中完成,但网络是在 Blazor 中完成的,所以会很好。

From Blazor .Net 5 RC1 https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-5-release-candidate-1/#blazor-webassembly-prerendering来自 Blazor .Net 5 RC1 https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-5-release-candidate-1/#blazor-webassembly-prerendering

in your hosting app you can use component tag helper with render-mode="Static" or render-mode="WebAssemblyPrerendered"在您的托管应用程序中,您可以使用带有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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM