You could use a simple for loop to get the index:
//use .Count if it is a List or .Count() with Linq to get the boundary.
@for(var i = 0; i < l_IEnumerableModUserQuery.Count; i++)
{
<tr>
<td>
@i.ToString();
</td>
<td>
<a href="#">
@l_IEnumerableModUserQuery[i].Pr_FullName
</a>
</td>
<td>@l_IEnumerableModUserQuery[i].Pr_Email</td>
<td>@l_IEnumerableModUserQuery[i].Pr_ContactNo</td>
</tr>
}
Thomas Levesque has a neat approach on his blog, using an extension method:
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> source)
{
return source.Select((item, index) => (item, index));
}
Which would result in:
@foreach (var (item, idx) in l_IEnumerableModUserQuery.WithIndex())
{
<tr>
<td>
@idx
</td>
<td>
<a href="#">
@item.Pr_FullName
</a>
</td>
<td>@item.Pr_Email</td>
<td>@item.Pr_ContactNo</td>
</tr>
}
With an eye on the extension methods approach, you could as well amend your views model and include the index as a property in your model inside your controller / handler or whereever your model is created:
var l_IEnumerableModUserQuery =
someSource.Where(x => ...)
.Select((x, index) => new MyModel {
Index = index,
Pr_Email = xxx,
Pr_Contact = xxy,
/* ... rest of model */
});
return l_IEnumerableModUserQuery;
After this you could access the index like any other property in your view:
<a href="#">
@item.Index
</a>