如何将Blazor组件呈现为HTML字符串 [英] How to render a Blazor component into an HTML string
本文介绍了如何将Blazor组件呈现为HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种将Blazor组件呈现为HTML字符串的方法,以便能够将其用作在Web应用程序中创建和发送电子邮件的模板引擎.想法?
I'm looking for a way to render a Blazor component into an HTML string, so that I'll be able to use it as a templating engine to create and send emails in my web application. Ideas?
推荐答案
是的,您可以使用Steve Sanderson提供的测试库并使其适应您的需求.
本文介绍了如何使用它: Blazor组件测试简介.
该库可用于生成组件的HTML.
Yes, you can use the test library provided by Steve Sanderson and adapt it to your needs.
This article explains how to use it : Introduction to Blazor Component Testing
.
The library can be use to generate the HTML of a component.
示例:
var host = new TestHost();
var component = host.AddComponent<YourComponent>();
var html = component.GetMarkup();
您可以注入所需的服务.
And you can inject services you need.
host.ConfigureServices(services =>
{
service.AddSingleton<MyService>();
});
这篇关于如何将Blazor组件呈现为HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文