簡體   English   中英

ASP.NET MVC4 WebGrid如何顯示WebGrid中的所有頁面

[英]ASP.NET MVC4 WebGrid how to display all pages in the WebGrid

我正在將具有1000行的模型傳遞給WebGrid。 我需要顯示它們40頁。 因此將有25頁。 但是,WebGrid僅顯示前五個鏈接,而當我選擇最后一個鏈接時,WebGrid會重新顯示2個鏈接,這有點麻煩。

WebGrid如何顯示所有頁面?

找到了我問題的部分答案。

@grid.GetHtml(
    mode: WebGridPagerModes.All,
    firstText: "<< First",
    previousText: "< Prev",
    nextText: "Next >",
    lastText: "Last >>",
...

這也可以通過手動處理webgrid分頁來完成。 通過使用int count = grid.PageCount獲取總頁數,您可以顯示所有頁碼,並使用簡單的循環使其超鏈接。例如

@{var grid = new WebGrid(source: [MODEL], defaultSort: "[COLNAME]", rowsPerPage: 15, canPage: true, canSort: true, sortFieldName: "[COLNAME]", sortDirectionFieldName: "ASC");
     int count = grid.PageCount;
     @grid.GetHtml(headerStyle: "HeaderClassCSS", footerStyle: "FooterClassCSS", rowStyle: "RowClassCSS", alternatingRowStyle: "AlternateRowClassCSS", columns: grid.Columns(
     grid.Column(columnName: "ChannelID", header: "ID"),
     grid.Column(columnName: "ChannelName", header: "Channel Name"),
     ), htmlAttributes: new { @class = "TableClassCSS" }, mode: WebGridPagerModes.All)
  }
  </div>
     <div style="text-align:center">
     @for (int i = 1; i <= count; i++)
     {
     //@Url.Action(,"Channels", new { page = i})
        <a href="@Url.Action("Channels", new { page = i})">@(i + " | " )</a>
      }
  </div>

注意:您可以通過使用分配給頁腳的類(在我的情況下為'FooterClassCSS')來禁用或隱藏內置頁腳。 喜歡

.FooterClassCSS
 {
    display:none;
 }

您可以在getHtml numericLinksCount:25中使用 ,此設置將在頁腳的滑動編號中顯示25頁號。

@grid.GetHtml(
                        mode: WebGridPagerModes.All,
                        numericLinksCount: 10,
                        firstText: "<< First",
                        previousText: "< Prev",
                        nextText: " Next >",
                        lastText: "Last >>",
                        tableStyle: "webgrid-table",
                        headerStyle: "webgrid-header",
                        footerStyle: "table-pager",
                        alternatingRowStyle: "webgrid-alternating-row",
                        rowStyle: "webgrid-row-style", columns: grid.Columns(
                            gridColumns.ToArray()
                            ));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM