2016-04-21 47 views
-1

我有MVC模式表它看起來像這樣:如何在html表MVC中給出序列號?使用CSS或jQuery的

<table id="example" class="table table-hover"> 
    <thead> 
     <tr> 
      <th>SL NO 
      </th> 
      <th>Designation Name 
      </th> 
      <th></th> 
     </tr> 
    </thead> 
    <tbody> 
     @foreach (var item in Model) 
     { 
      <tr> 
       <td> 
//Here I want Serial No here [I used Paging] 
       </td> 
       <td> 

        @Html.DisplayFor(modelItem => item.desigantionName) 
       </td> 
       <td> 
        <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Edit", "Edit", new { id = item.desigantionId }) </div> 
        <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Details", "Details", new { id = item.desigantionId }) </div> 
        <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Delete", "Delete", new { id = item.desigantionId })</div> 
       </td> 
      </tr> 
     } 
    </tbody> 
</table> 

上面的代碼中第一欄我想序列號我用SL沒有用CSS,但問題是進入下一個頁面索引SL在沒有resart高達1 每個尋呼機我用5行我需要啓動第二頁索引sl沒有達到6

+0

如何檢索模型?獲取模型數據時必須注意偏移量。你可以在模型中添加一些索引嗎? – derpirscher

+0

你的問題幾乎沒有意義。你怎麼可能使用jQuery或CSS來渲染出序列號?除非你的意思是'索引',或者你只是想要每個項目的序列號,比如'1,2,3,4, 5,6,7,8'(在這種情況下@derpirscher說,你必須知道偏移量)? 如果你確實指的是序列號,它必須是你正在渲染的項目的一個屬性,它必須是唯一的,所以你不能在前端簡單地生成它,它與分頁沒有任何關係。爲什麼你不能渲染'item.serialNumber'或者其他什麼屬性被調用? – DanCouper

回答

0

做這樣的事情,如果你想打印模型中的序列號數據。 pagesizepageNum應根據當前頁碼和其大小設置

   <tbody> 

       @{ int i = 0; }      
        @foreach (var item in Model) 
        { 
         <tr> 
          <td> 
           <label>pageSize * (pageNum - 1) + @i</label> //your serial no 
           @{ i++; }  
          </td> 
          <td> 

           @Html.DisplayFor(modelItem => item.desigantionName) 
          </td> 
          <td> 
           <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Edit", "Edit", new { id = item.desigantionId }) </div> 
           <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Details", "Details", new { id = item.desigantionId }) </div> 
           <div class="btn btn-default btn-lg disabled p-x-2">@Html.ActionLink("Delete", "Delete", new { id = item.desigantionId })</div> 
          </td> 
         </tr> 
        } 
       </tbody 
+0

這隻適用於第一頁。明確地說,他使用分頁,並希望第二頁上的索引開始,例如,5.您的方法將始終打印0,1,... – derpirscher

+0

我已更新頁面大小的答案.... 。 – sumngh

相關問題