I am working in MVC Core using EntityFramework. How can I get the row number in view in the table?
My model is:
public class Provider{
public int ProviderId { get; set; }
public string Name { get; set; }
public int DateOfBirth{ get; set; }
}
Controller is:
public async Task<IActionResult> Index()
{
return View(await _context.Provider.ToListAsync());
}
View Is:
@model IEnumerable<Project.Provider>
@foreach (var item in Model) {
<tr>
<td>
#
</td>
<td>
@Html.DisplayFor(modelItem => item.ProviderId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfBirth)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfBirth)
</td>
}
output:
100 | Foo | 10/10/1990|
101 | Bar | 10/10/1990|
I want a row number at the start, output like:
1|100 | Foo | 10/10/1990|
2|101 | Bar | 10/10/1990|