Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvc view table row number counter

I have a table than shown one record of my model. for example list of category. i want to create manually row number for this table.

<table class="table table-striped table-bordered table-hover table-full-width dataTable">
  @foreach (var item in Model)
  {   
    <tr>
      <td>
        **I want to Show Row Number Here**
      </td>
      <td>
        @Html.ActionLink(item.Name, "ViewSubCategory", "ProductSubCategory", new { id = item.Id }, null)
      </td>
    </tr>
  }
</table>
like image 861
Moein Avatar asked Nov 28 '22 13:11

Moein


2 Answers

Define a counter rowNo and write

@{ int rowNo = 0; }

@foreach (var item in Model) {       
<tr style="background: @classtr;" >
    <td>
        @(rowNo += 1)
    </td>
like image 72
hasan Avatar answered Dec 09 '22 17:12

hasan


Define a counter rowNo and write

<table class="table table-striped table-bordered table-hover table-full-width dataTable">

  @{int rowNo;}

  @foreach (var item in Model)
  {   
    <tr>
      <td>
       @rowNo++;
      </td>
      <td>
        @Html.ActionLink(item.Name, "ViewSubCategory", "ProductSubCategory", new { id = item.Id }, null)
      </td>
    </tr>
  }
</table>
like image 30
Murali Murugesan Avatar answered Dec 09 '22 17:12

Murali Murugesan