PagedList 在第二页和之后的页面上丢失了搜索过滤器

我丢失了第二页上的所有数据,然后丢失了。第一个结果/页面显示了正确的数据。第二页之后,没有数据。


我的代码:


public ActionResult Contact(int? pageNumber, string search, string option, string select)

    {

        if (option == "Company")

        {            

            return View(db.CompaniesServers.Where(x => x.Name.Contains(search)).ToList().ToPagedList(pageNumber ?? 1, 2));

        }

        else

        {

            return View(db.CompaniesServers.ToList().ToPagedList(pageNumber ?? 1, 3));

        }

    }

我的看法 :


@using PagedList;

@using PagedList.Mvc;


@model IPagedList<WorkingWithData.Models.CompaniesServer>



@using (Html.BeginForm("Contact", "Home", FormMethod.Get))

            {


    <b>

        Search Options: <br />

    </b>@Html.RadioButton("option", "Company") <text>Company Name</text> 

    @Html.TextBox("search", null, new { style = "height:30px" })  <select id="serverList" style="height:33px; font-size:small" class="btn btn-default">

                    <option value="All">Select Server</option>

                    <option value="10.67.21.40">Lam Server 4</option>

                    <option value="10.67.21.47">Lam Server 14</option>

                    <option value="10.67.21.70">Lam Server 12</option>

                </select> <a class="btn btn-default" href="/Home/Contact">Reset</a>    <input type="submit" name="submit" value="Search" class="btn btn-primary" />

                

}


<table class="table">

    <tr>

        <th>

           Address

        </th>

        <th>

           Port

        </th>

        <th>

           Name

        </th>

        <th>

          Environment

        </th>

        <th>

           Active

        </th>

        <th></th>

    </tr>


第一页结果返回有效信息。但是当我进入第二页时,什么也没有出现。我的变量在调试时返回 null。


我应该尝试停止页面加载吗?虽然 MVC 是新的。


FFIVE
浏览 123回答 2
2回答

芜湖不芜

我找到了答案。我真的不想使用ViewBag,但我不得不使用。似乎我需要在每次分页时存储/发回我的“选项”和“搜索”值。起初,我只是存储“pageNumber”。在我的控制器中添加:&nbsp;ViewBag.Search1 = option;&nbsp;ViewBag.Search2 = search;进入查看,在分页部分添加PagedListPager:option = ViewData["Search1"];search = ViewData["Search2"];
打开App,查看更多内容
随时随地看视频慕课网APP