Aspnetcore: Blazor RZ9986 — Component attributes do not support complex content (mixed C# and markup)

Created on 30 Apr 2019  Â·  9Comments  Â·  Source: dotnet/aspnetcore

I've found that this issue was already fixed in 0.4.0
Reference 1
Reference 2

But it still present.
Blazor 3.0.0-preview4
Visual Studio 2019 16.1.0 preview2
Latest vsix extension installed

Files where issue happened:
Button.razor
HalfButton.razor

Project repository

I also tried to solve this problem by deleting .vs / bin / obj directories and restarting VS.

affected-most area-blazor enhancement severity-minor

Most helpful comment

You can also use:

@if (Disabled) {
    <button class=@($"w3-{Color}")>Click me</button>
}

All 9 comments

image

Currently we don't support concatenation of strings inside the values of attributes passed to components. You can work around the issue by doing the concatenation separately and then pass in the value.

@danroth27 so you mean replace

Color="red"
... w3-@(Color) ...

With

Color="w3-red"
... @(Color) ...
?

Instead of this:

@if (Disabled) {
    <button class="w3-@(Color) ... " >...</button>
}

I think you can do this:

@if (Disabled) {
    var classText = "w3-" + Color + .... ;
    <button class="@classText" >...</button>
}

You can also use:

@if (Disabled) {
    <button class=@($"w3-{Color}")>Click me</button>
}

This is pretty important IMHO. At the moment you can't even pass an id into a NavLink helper. Strange that it used to work.

I solved it by diff way...

 var link = "SomeOtherUrl/" + forecast.SomeValue;
                    <tr>
                        <td>@forecast.SomeValue</td>
                        <td>
                            <NavLink class="nav-link" href="@link">
                                <span class="oi oi-plus" aria-hidden="true"></span> Detail
                            </NavLink>
                        </td>
                    </tr>

will this problem be addressed?

Hi @burakakca. Currently this issue is on our backlog with no committed time frame to address it. So I wouldn't expect it to be addressed any time soon. In the meantime you can use the various workaround described in the earlier comments.

Was this page helpful?
0 / 5 - 0 ratings