Skip to content

Confused by error message regarding attribute syntax #12190

@pekspro

Description

@pekspro

I’ve just started to play around with Blazor and tried to write this code in a .razor-file:

<span class="@if(sortType != 0) { <text>btn-primary</text> } else { <text>btn-success</text> }">

Yes, not very elegant :-) Either way, I got this error message that confuses me:

Code blocks delimited by '@{...}' like '@{ if(sortType != 0) { } }' for attributes are no longer supported These features have been changed to use attribute syntax. Use 'attr="@(x => {... }"'.

I’ve tried to rewrite me code to use lambda expression as suggested, but whatever I do a get an error message. Is this possible in this case? I’ve noticed that a lambda expression works fine if the attribute is @onclick.

If I rewrite my code like this it works, but that is not was the error message suggest:

<span class="btn @(sortType != 0 ? "btn-primary" : "btn-success")">

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions