Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4841

Error Encountered When Dynamically Adding Attribute to Razor Component in C# Blazor

$
0
0

I have a Differ_Board.razor file with the following content:

<div class="dsb-container" draggable="true"><BoardHeader></BoardHeader></div>@code {    [Parameter]    public DashBord_Info Dash_Channel_Info { get; set; }}

BoardHeader

<div class="dsb-title"><div style="display: flex;                        align-items: center;                        justify-content: center;"><span>@Title</span></div></div>@code {    [Parameter]    public RenderFragment ChildContent { get; set; }    [Parameter]    public string Title { get; set; } = "Test";}

I am using the following method to dynamically add the Dash_Channel_Info variable:

RenderFragment<DashBord_Info> renderFragment = value => builder =>{    builder.OpenComponent(0, Type.GetType($"{namespaceName}.{dashboardType}"));    builder.AddAttribute(1, "Dash_Channel_Info", value);    builder.CloseComponent();};

I have confirmed that the variable is correctly passed, but <BoardHeader></BoardHeader> triggers the following error:

Unhandled exception rendering component: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': ');"' is not a valid attribute name.

The error disappears when I remove builder.AddAttribute(1, "Dash_Channel_Info", value);.

But I need to use AddAttribute for dynamic generation.

I need assistance in resolving this issue. Thank you.


Viewing all articles
Browse latest Browse all 4841

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>