ASP.NET MVC Pagedlistpager pagination with more than one parameter

Asked

Viewed 674 times

1

I have the following page using x.Pagedlist

@using AspNet.Models;
@using X.PagedList.Mvc

@{

ViewBag.Title = "Visualiza";
@model X.PagedList.IPagedList<AspNet.Models.Pessoa>

}

<h2>Pessoas Cadastradas</h2>
<div class="table-responsive">
<table class="table table-bordered table-hover table-inverse">
    <thead>
        <tr>
            <th>Nome</th>
            <th>Idade</th>
            <th>Usuario</th>
            <th>Setor</th>
            <th>Sub Setor</th>
            <th>Editar</th>
        </tr>
    </thead>
    <tbody>
        @foreach (Pessoa pessoa in Model)
        {
            <tr>
                <td>@pessoa.nome</td>
                <td>@pessoa.idade</td>
                <td>@pessoa.usuario</td>
                <td>@pessoa.setor</td>
                <td>@pessoa.sub_setor</td>
                <td>@Html.ActionLink("Editar", "Edita", "Pessoa", new { 
 @id_pessoa = pessoa.id_pessoa }, null)</td>
            </tr>
        }
    </tbody>
  </table>
 </div>
  Página @Model.PageNumber de @Model.PageCount
  @Html.PagedListPager(Model, page => Url.Action("Visualiza","Pessoa", new 
  {pagina = page}) + "&setor=" + ViewBag.setor)

Note that in the URL.Action above I am passing two GET parameters, the page and the sector... when the page is generated, it generates the link of get:

inserir a descrição da imagem aqui

However, when I go to page 2 and want to go back to 1, it loses the get sector: inserir a descrição da imagem aqui

Can someone help me with this?

  • 1

    I got it done. i was specifying the wrong action... the correct one would be @Html.Pagedlistpager(Model, page => Url.Action("Viewbag","Person", new {page = page}) + "&sector=" + Viewbag.sector)

  • Answers your question with that answer to document.

1 answer

0


I’ve already done it. I was specifying the Action wrong. The right would be:

@Html.PagedListPager(Model, page => Url.Action("VisualizaPorSetor","Pessoa", new {pagina = page}) + "&setor=" + ViewBag.setor)

Browser other questions tagged

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