Could some one point out how to include a Serial Numbe开发者_开发知识库r 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>
}
@foreach (var item in Model )
{
<tr>
<td> @( ((Int32) 1) + @Model.IndexOf(item) ) </td>
</tr>
}
@{int index = 1;}
@foreach (var item in Model)
{
<tr>
<td>
@index
</td>
</tr>
index++;
}
<tbody>
@{
int sno = 0;
}
@foreach (var item in Model)
{
<tr>
<td>
@{ sno++; }
@sno
</td>
</tr>
}
</tbody>
@{ int i = 1; }
@foreach (var item in Model) {
<tr>
<td>
@i
</td>
@{ i++; }
<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>
@foreach (var item in Model) {
<tr>
<td>
@(Model.ToList().IndexOf(item) + 1)
</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>
}
精彩评论