Not changing the page when changing the page

Asked

Viewed 57 times

0

When I try to go to page 2, it shows the site loading, but only brings me the first page information of my page 1. My Controller:

public ActionResult Index(int? page)
    {
        IList<Abastecimento> abastecimento = dao.Lista();
        page = 1;
        int NumRegistro = 10;
        int NumPag = (page ?? 1);
        return View(abastecimento.ToPagedList(NumPag, NumRegistro));
    }

My View:

 Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
  • You have to pass the page number to the method Lista() and make the method return only the amount of items referring to that page. In this code, the method Lista() brings everything from the bank and makes the pagination on controller. When you have thousands of records, a page will take too long to display.

2 answers

0

Remove this line from your code

page = 1;

It will work. You are always putting the value 1 in the variable.

  • I withdrew and still do not exchange page.

  • I believe the error is in mounting your pagination link. Note that you create the parameter to be passed, but do not feed it with values:

  • @Html.Pagedlistpager(Model, page => Url.Action("Index", new { page })) Missing add something here: new { page = XXXXXX }))

  • To solve I put Viewresult in place of Actionresult

0


I traded the Actionresult for a Viewresult.

public ActionResult Index(int? page)
    {
        IList<Abastecimento> abastecimento = dao.Lista();
        page = 1;
        int NumRegistro = 10;
        int NumPag = (page ?? 1);
        return View(abastecimento.ToPagedList(NumPag, NumRegistro));
    }

For:

public ViewResult Index(int? page)
    {
        IList<Abastecimento> abastecimento = dao.Lista();
        page = 1;
        int NumRegistro = 10;
        int NumPag = (page ?? 1);
        return View(abastecimento.ToPagedList(NumPag, NumRegistro));
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.