Tuesday, 7 May 2019

Show Serial number for Table column

Some time we retrieve data from the database and render in the table and we want to show serial number, then this article will help you to show the serial number using foreach loop  using razor.



<table class="table table-bordered table-hover">
    <thead>

        <tr>
            <th align="center">Sr No.</th>
            <th align="center">Leave Type</th>
            <th align="center">Quantity</th>
        </tr>
    </thead>
    <tbody>
        @{int i = 1;}

        @foreach (var item in Model.ConsumeLeave)
        {
            <tr>
                <td>@i</td>
                <td>@item.LeaveName</td>
                <td>@item.LeaveCount</td>
            </tr>
            i++;
        }
    </tbody>
</table>



No comments:

Post a comment