我想通过风格Attribute
(设置div的宽度使用DIV作为引导进度条。我想这样做在foreach
循环中的foreach ASP.NET MVC剃刀设置样式属性
@foreach (var item in Items)
{
<tr>
<td>@item.Name</td>
<td>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="@item.PercentageCompleted" aria-valuemin="0" aria-valuemax="100" style="width: @item.PercentageCompleted;">
</div>
</div>
</td>
</tr>
} `
什么情况是,风格attribute
是空的。有没有办法实现这一目标?
“PercentageCompleted”的值是多少?他们只是一个数字,或者他们是'## px','##%''等等? –
它们只是一个数字,但对于项目列表中的每个条目都是不同的。 – crauscher
经过测试,它确实生成'style'属性,但它不会有效 - 您需要像'style =“@ string.format(”width:{0}%;“,item.PercentageCompleted)”'使其有效 –