假设我有一个for循环来生成表格中的元素:
@for (var i = 0; i < Model.Count(); i+=2) {
<tr>
@{var a = Model.ElementAt(i); var b = Model.ElementAtOrDefault(i + 1);}
<td>
<div id="r@i" class="rack-container">
...
</div>
<div id="s@i" class="rack-selector fade">
...
</div>
</td>
<td>
@if (b != null) {
<div id="r@i+1" class="rack-container">
...
</div>
<div id="s@i+1" class="rack-selector fade">
...
</div>
}
</td>
</tr>
}
问题是该元素按字面意思分配为“r @ i”而不是“r1”,“r2”......“rN”等等。有没有办法将文本和变量组合为元素ID?