Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 368
Simon Avatar asked Jan 19 '21 14:01

Simon


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>  
like image 184
Simon Avatar answered Nov 15 '22 08:11

Simon


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

<div class="progress-bar" style="width: @(Progress)%;"></div>
like image 32
Henk Holterman Avatar answered Nov 15 '22 08:11

Henk Holterman