2016-04-21 46 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

相关问题