Could someone help me get this razor syntax snippet to compile?
@var count = 0;
@foreach (var column in Enumerable.Range(0, 20).Select(i => "Title " + i) {
if(count % 5 == 0) {
<tr>
}
<td>@column</td>
@if(count % 5 == 4) {
</tr>
}
count++;
}
You do not need the
countvariable. I’ve made an alternative solution to Darin´s answer:As you can see in Darin´s answer and this answer, you don’t need
@when you are inside a block. Furthermore, your<tr>and</tr>look “uneven” to the compiler, so we have to force these with@:<tr>. And last,@var count = 0will have to be in a block like@{var count = 0}.Update: If you actually need an index (if you’re not using
Range()) then you can do as follows (using the overload ofSelectwhich generates an index for each item):