I want to display incremental values at the first column of following code inside Sr. No. column in ASP.net MVC Razor view. I am doing following but its not working. It showing 0++; only in that column. what wrong I am doing.
 @{int i = 0;}
 <table class="table">
 <tr>
    <th>Sr No.</th>
    <th>
        @Html.DisplayNameFor(model => model.Name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.ModifiedDate)
    </th>
    <th></th>
 </tr>
 @foreach (var item in Model)
 {
    <tr>
        <td>
            <span>@i++;</span>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ModifiedDate)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.CurrencyCode }) |
            @Html.ActionLink("Details", "Details", new { id = item.CurrencyCode }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.CurrencyCode })
        </td>
    </tr>
 }
                In razor syntax you should create C# scope for C# logical statemens. Can you try the the code below;
<td>
    <span>@(i++)</span>
</td>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With