MVC3 Pagination, paragraphs per page

I need to implement pagination, number of elements per page and sorting for my MVC3 application. On my browse page, I have a list of items that come from the model. I will display several elements (user-defined) each inside a div, per page. I am not building a table.

I know that mvccontrib can create a paging table, and am not sure if this pagination can be written at all, because I need to create mine. What is a good approach to solving this?

+4
source share
4 answers

Check out the PagedList (available as a nuget package) . So far, I found it really mvc friendly.

+2
source

For server side paging, I use https://github.com/dvsspr/Halaman . It has not yet been documented, but it is very flexible and uses a smooth configuration.

One simple use case for you.

@Controller

public ActionResult Index(AdminPageInfo page, SortInfo sort) { PagedData<Account> model = accountRepository.Get().AsPagedData(page, sort); return (model.IsValid) ? View(model) : View("_Error"); } 

@View

 @model PagedData<Account> @{ ViewBag.Title = "Account Index"; } <p> Total records: <strong>@Model.TotalRows</strong> <br /> Total pages: <strong>@Model.TotalPages</strong> <br /> Total records in current page: <strong>@Model.TotalRowsInPage</strong> </p> @Html.Pager(Model) @Html.Sizer(Model) @* Page size changer helper =) *@ @* Put a dot after the closing brace and you will see the available options. *@ <h3>Sorter</h3> <li> <ul>@(Html.SortLink<Account>(zz => zz.Id, Model, "User Id"))</ul> <ul>@(Html.SortLink<Account>(zz => zz.UserName, Model, "User Name"))</ul> <ul>@(Html.SortLink<Account>(zz => zz.FullName, Model, "Full Name"))</ul> </li> @foreach (var acc in Model) { <p> User name: @acc.UserName <br /> Full name: @acc.FullName </p> } 

What is it. IMHO, the code base can be easily cracked - just in case you want to implement hybrid paging.

+1
source

If you are looking primarily for a client solution, I have never had problems with jQuery Tablesorter with the Paginator plugin: http://tablesorter.com/docs/example-pager.html

If you want to make this server part, the general approach is that you are going to cache the entire server side of the result set *, and then make (ajax or otherwise) calls to the server, indicating which entries are needed. You will pass in the starting index and the number of records to be returned via a querystring or form field (as well as some request identifier to make sure that you get the correct result set).

* As mrjoltcola notes in the comments, whether or not to cache is a random problem, for larger result sets it may make more sense to make more db calls with smaller result sets. An alternative solution to the problem with a large number of results limits their size of the result set and displays a message prompting them to make their query more specific if the threshold value is exceeded. I would advise you first to come from your best opinion and optimize if necessary .

0
source

With simple HTML, you can use Webgrid help in WebMatrix. It supports paging out of the box with MVC.

http://msdn.microsoft.com/en-gb/magazine/hh288075.aspx

Otherwise, any of the main components of Javascript (jqgrid, extjs, etc.) can perform swapping, it all depends on which source of your model. If you use an AJAX data source, you need to pass the swap properties back and forth, so paging can be efficiently done on the server side (depending on the database of your database).

0
source

Source: https://habr.com/ru/post/1369020/


All Articles