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+"%"

 

posted @ 2020-12-30 18:25  ChuckLu  阅读(75)  评论(0编辑  收藏  举报