How to fix Blazor/Razor warning: Unexpected character sequence in property value

Viewed 445

In our Blazor-App we want to apply the width of an htmle-element by the style-attribute and an binding:

<div class="progress-bar" style="width: @Progress%;"></div>

@code {

    [Parameter]
    public int Progress { get; set; }
}

Problem: Visual Studio shows me an warning: "Unexpected character sequence in property value"

enter image description here

This warning has no CL... or BL... code.

Question: What is an elegant way to fix this warning?

2 Answers

I found a possible solution now, based on Henk Holterman“s answer which not shows the warning any more:

<div class="progress-bar" style="width: @($"{Progress}%");"></div>  

Blazor sometimes needs a little help to find the C#/HTML border. @(...) usually does the trick.

<div class="progress-bar" style="width: @(Progress)%;"></div>
Related