Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increment in asp.net mvc razor view

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>
 }
like image 508
Prakash Joshi Avatar asked Mar 11 '23 00:03

Prakash Joshi


1 Answers

In razor syntax you should create C# scope for C# logical statemens. Can you try the the code below;

<td>
    <span>@(i++)</span>
</td>
like image 105
Cihan Uygun Avatar answered Mar 23 '23 04:03

Cihan Uygun