nitorB
nitorB

Reputation: 11

how to perform pagination in List inside a model in mvc razor

I have a model like:

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; }
}

Now in razor view, if we call the model like

@model MvcApp.Models.Customer

how to perform paging operation on ContactList that is inside the Customer model using PagedList or something.

Any help ?

Thanks in advance

Upvotes: 1

Views: 865

Answers (1)

Ssheverdin
Ssheverdin

Reputation: 111

If you want easy client side pagination then https://datatables.net/ would be your best option. Put Contacts into PartialView, make list displayed as table, apply datatables module, and it should look good. If you want to use IPagedList then you would have to reload view every time when user clicks new page, because IPageList return one page at the time, and use of it on client side is not very good practice. However if you are ready to server calls:

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

Just load ContactList with page data on Server side every time when user clicks page.

Upvotes: 1

Related Questions