asp.net-mvc MVC 5 中的分页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22194716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:34:09  来源:igfitidea点击:

Paging in MVC 5

asp.net-mvcrazorpaginationhtml-table

提问by Golda

In MVC 5, how to create paging for table? The following is a table structure.

在 MVC 5 中,如何为表创建分页?下面是一个表结构。

<table class="table">
    <tr>
        <th>
           Item ID
        </th>
        <th>
           Item Name
        </th>
        <th>
           Rate
        </th>
        <th>
          Stock
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ItemID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Rate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Stock)
        </td>
    </tr>
}    
</table>

回答by Osman M Elsayed

I recommend the PagedList package which is available on nuget

我推荐 nuget 上提供的 PagedList 包

https://www.nuget.org/packages/PagedList

https://www.nuget.org/packages/PagedList

Here is the full documentation

这是完整的文档

https://github.com/TroyGoode/PagedList

https://github.com/TroyGoode/PagedList

回答by Golda

I have found the solution. Using webgrid, we can achieve the paging

我找到了解决方案。使用webgrid,我们可以实现分页

@model IEnumerable<ItemMaster>
@{
    ViewBag.Title = "Item Details";
    WebGrid grid = new WebGrid(Model,rowsPerPage:5);
}
<h2>Item Details</h2>
@grid.GetHtml()

回答by Maz H

Grid.MVCis an open source and working Grid with sorting and paging

Grid.MVC是一个开源的工作网格,具有排序和分页功能

(and unlike telerik you do not need to change anything on controller side just add reference in your view and use.)

(与 Telerik 不同,您无需在控制器端更改任何内容,只需在您的视图中添加引用并使用即可。)

To install nugget package (Install)

安装 nugget 包(安装

PM> Install-Package Grid.Mvc -Version 3.0.0 

In your view you can auto-create columns as below (or customize see User Guide)

在您的视图中,您可以自动创建如下列(或自定义,请参阅用户指南

@using GridMvc.Html

@Html.Grid(Model).AutoGenerateColumns()

See Online Demo

在线演示

回答by Tajveer Singh Nijjar

you can look for DataTables jquery plugin here. It is a very powerful and light weight plugin that supports sorting and searching inside the table.

您可以在此处查找 DataTables jquery 插件。它是一个非常强大和轻量级的插件,支持在表格内进行排序和搜索。