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?
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.
exemple :
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>();
});
Agua's original answer is still good.. however
A new solution now available for this question: BlazorTemplater is a library I wrote to address this capability (as I needed this for my app!).
This library will render any .razor
component to HTML for use in emails. Supports nested components, properties, dependency injection, and can be used in Razor Component libraries.
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.
exemple :
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>();
});
© 2022 - 2024 — McMap. All rights reserved.