You are not changing the page when you change the pagination

0

When I'm trying to go to page 2, it shows the site loading, but it only brings me the first information on page 1 of my page. 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 }))
    
asked by anonymous 18.09.2017 / 22:45

2 answers

0

I changed the ActionResult to 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));
    }

By:

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));
    }
    
19.09.2017 / 22:30
0

Remove this line from your code

page = 1;

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

    
19.09.2017 / 18:49