現在、CSHTMLで次のコードを使用しています。
@{int i = 0;}
@foreach (var item in Model.Traders)
{
if ((i++ % 3) == 0) {
if (i != 1) {
@:</div>
}
@:<div class="row">
}
@:<div class="four column"><div class="panel new"><h3 class="dotted"><strong>@item.Title</strong></h3><p>@item.Description</p><code><div class="panel pick"></code></div></div>
}
@if (i != 0) {
@:</div>
}
これにより、次のHTMLが出力されます。
<div class="row">
<div class="four column"><div class="panel new"><h3 class="dotted"><strong>Title</strong></h3><p>Description</p><code>code</code></div></div>
<div class="four column"><div class="panel new"><h3 class="dotted"><strong>Title</strong></h3><p>Description</p><code>code</code></div></div>
<div class="four column"><div class="panel new"><h3 class="dotted"><strong>Title</strong></h3><p>Description</p><code>code</code></div></div>
</div>
<div class="row">
<div class="four column"><div class="panel new"><h3 class="dotted"><strong>Bobby</strong></h3><p>Bobby bobby bobby</p><code><div class="panel pick"></code></div></div>
<!-- Add missing divs if there's less than 3 (there always needs to be 3 divs inside a div row). In this case it's 2 that are missing -->
<div class="four column"></div> <!-- my code does not render these -->
<div class="four column"></div> <!-- my code does not render these -->
</div>
私の質問は、自分のビュー内で行っていることを達成し、行に3つ未満の場合に、欠落しているdivを確実に追加する簡単な方法があるかどうかです。