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