Concatenating the Razor Variables with CSS Styles

Concatenating the Razor Variables with CSS Styles

Try this:

<div style="background-image: url('@Model.SpriteSheetUrl'); width: 60px; height: 60px;background-position: 0px @(positionY + "px"))> </div>

The @() renders whatever is written inside of it as a literal, so you should get "60px" as the output.

 

拼接

var widthPercentage = 0;
if (selfRegistrationIsPublished)
{
widthPercentage = 20;
}
else
{
widthPercentage = 25;
}

 <div class="col" style="width: @(widthPercentage+"%")">

@()在括号里面写widthPercentage+"%"

 

上一篇:c#-.net核心AspnetCore剃刀视图因CompilationFailedException而失败


下一篇:.net 5 mvc Razor语法