在我看来,我写的是这样的:
@Code
For Each item in Model
@<div class="col-md-2">
<img class="img-responsive" src="~/thumbs/@(item.username).png" alt="">
</div>
Next
End Code
这很好用!但是,我想添加一些额外的代码行,这些代码应该在循环的每第6次迭代中执行(从0开始)。所以我修改了如下代码:
@Code
Dim count As Integer = 0
For Each item in Model
@IIf(count Mod 6 = 0, "<div class='row'>", "") ' This line Executes on every 6th iteration
@<div class="col-md-2">
<img class="img-responsive" src="~/thumbs/@(item.username).png" alt="">
</div>
@IIf(count Mod 6 = 0, "</div>", "") ' This line Executes on every 6th iteration
count += 1
Next
End Code
但不是添加标记<div class='row'>
和</div>
;它在页面上写下原始字符串(好像我已经写了<div class='row'>
和</div>
)!我该怎么办?
答案 0 :(得分:0)
好的,伙计们;我得到了答案。我做的是:
@Code
Dim count As Integer = 0
For Each item in Model
@IIf(count Mod 6 = 0, @Html.Raw("<div class='row'>"), "") ' This line Executes on every 6th iteration
@<div class="col-md-2">
<img class="img-responsive" src="~/thumbs/@(item.username).png" alt="">
</div>
@IIf(count Mod 6 = 0, @Html.Raw("</div>"), "") ' This line Executes on every 6th iteration
count += 1
Next
End Code