Is it possible to render <component>
tags inside .razor
files. I have a requirement where a static script needs to be rendered inside another Blazor component. So, I have created the script tags using BuildRenderTree
concept and tried to add the <component>
tag with render-mode
as Static
. But, it won't render in the web page.
ScriptRender.razor
public class ScriptRender : ComponentBase
{
[Parameter]
public List<string> Source { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
foreach (var scriptPath in Source)
{
builder.OpenElement(0, "script");
builder.AddAttribute(1, "src", scriptPath);
builder.CloseElement();
}
}
}
BlazorComponent.razor
<component type="typeof(ScriptRender)" render-mode="Static"></component>
// Rest of component rendering logics
I know, the <component>
tags can be used in the layout.cshtml pages. Isn't working in Blazor razor pages?