Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Component attributes do not support complex content (mixed C# and markup)

Tags:

c#

razor

blazor

I am trying to use a Razor argument and pass it into Blazor for further processing, but I get this error message "Component attributes do not support complex content (mixed C# and markup)" on the @onclick event I am trying to build on the img tag below:

<tr>

            @{
                for (int j = 0; j < Candidates.Length; j++)
                {
                    <th>
                        <div class="grow">

                            <img src="/Candidates/@(Candidates[j].ToString()).jfif" alt="@Candidates[j].ToString()" @onclick="IncrementScore(@j)" />
                        </div>
                    </th>
                }
            }
        </tr>

Any suggestions would be greatly appreciated!

like image 604
Øyvind Vik Avatar asked Feb 06 '20 02:02

Øyvind Vik


1 Answers

I came to this page in search for a solution for the same error:

Component attributes do not support complex content (mixed C# and markup)

In my case was all about the href link construction. I followed your solution on the accepted answer comment and it worked. Thanks @Øyvind Vik

Just in case it help others i'll leave my code as an example.

foreach (List<string[]> lss in searchResults)
            {
                var link = $"genericform/{entidadeSelecionada}/{lss.FirstOrDefault()[1]}";
                <tr>
                    @foreach (string[] st in lss)
                    {
                        if (camposAListar.Contains(st[0].ToLower()))
                        {
                            <td>@st[1]</td>
                        }
                    }

                    <td>
                        <NavLink href="@link">
                            <span class="oi oi-list-rich" aria-hidden="true"></span> Utilizador
                        </NavLink>
                    </td>
                </tr>
            }
like image 80
Ricardo Araújo Avatar answered Sep 20 '22 21:09

Ricardo Araújo