Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serial Number (Record Count) in Razor?

Could some one point out how to include a Serial Number while populating from a table on a Razor page view.

Here's my view

@foreach (var item in Model) {
    <tr>
        <td>
            ---- ??? HOW TO INCLUDE SERIAL NUMBER HERE ??? ----
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.studentName)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.studentID }) |
            @Html.ActionLink("Details", "Details", new { id = item.studentID }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.studentID })
        </td>
    </tr>

}

(Im using EF 4.1 scaffolding to autogenerate the contexts and models)

like image 722
Question Guy Avatar asked Dec 02 '22 01:12

Question Guy


1 Answers

@item.Serial

If you don't want to show it in an html control. You don't need to do anything special.

EDIT: It seems you just want a counter change the loop in your code to

@foreach (var item in Model.Select((x, i) => new { Data = x, Index = i }))
{
<tr>
    <td>
        @item.Index
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Data.studentName)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id = item.Data.studentID }) |
        @Html.ActionLink("Details", "Details", new { id = item.Data.studentID }) |
        @Html.ActionLink("Delete", "Delete", new { id = item.Data.studentID })
    </td>
</tr>

}

like image 106
Muhammad Hasan Khan Avatar answered Dec 27 '22 12:12

Muhammad Hasan Khan