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)
@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>
}
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