如何在mvc razor中的模型内的List中执行分页

时间:2017-06-07 11:09:02

标签: asp.net-mvc asp.net-mvc-4 razor pagedlist

我有一个类似的模型:

public class Customer
{
    public string Name { get; set; }
    public string Address { get; set; }
    public List<Contacts> ContactList { get; set; }
}
public class Contacts
{
    public string Name { get; set; }
    public string Phone { get; set; }
}

现在在razor视图中,如果我们将模型称为

@model MvcApp.Models.Customer

如何使用PagedList或

客户模型内的 ContactList 上执行分页操作。

任何帮助?

提前致谢

1 个答案:

答案 0 :(得分:0)

如果您希望轻松进行客户端分页,那么https://datatables.net/将是您的最佳选择。将联系人放入PartialView,使列表显示为表,应用数据表模块,它应该看起来不错。如果你想使用IPagedList,那么你每次用户点击新页面时都必须重新加载视图,因为IPageList当时返回一页,而在客户端使用它并不是很好的做法。但是,如果您准备好进行服务器呼叫:

public class Customer
{
    public string Name { get; set; }
    public string Address { get; set; }
    public IPageList<Contacts> ContactList { get; set; }
}

每次用户点击页面时,只需在服务器端加载ContactList和页面数据。