I am trying to put a row counter in index view
of my mvc project to count the items .my code is like this :
@{ int a = 0; }
@foreach (var item in Model) {
<tr>
<td>
@a=a+1;
</td>
</tr>
}
But the result is 0=a+1;
Could you please give me some help .
This should work if you want to start counting rows from zero:
<td>@(a++)</td>
In case of counting from one, use preincrementation:
<td>@(++a)</td>