PagedListPager不会在控制器

时间:2016-06-01 11:48:03

标签: c# asp.net-mvc razor pagedlist

PagedListPager不会触发控制器中的实际操作。 pagedlistpager永远不会调用Index Post动作。这是我的方法。

    // Get
    public ActionResult Index(string searchItem = "")
    {
        var categories = _categoryService.GetAllCategories(new GetCategoriesInput { Filter = searchItem.ToLower() });
        var model = categories.ToPagedList(1, 10);
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(string searchItem, int? page)
    {
        if (page == null)
        {
            var categories = _categoryService.GetAllCategories(new GetCategoriesInput { Filter = searchItem.ToLower() });
            var model = categories.ToPagedList(1, 10);
            return View(model);
        }
        else
        {
            var categories = _categoryService.GetAllCategories(new GetCategoriesInput { Filter = searchItem.ToLower() });
            var model = categories.ToPagedList((int)page, 10);
            return View(model);
        }

    }

最后是我的观看页面。

    @using PagedList.Mvc;
    @using PagedList;

    @model IPagedList<Categories.CategoryListDto>

    <div class="text-center">
       @Html.PagedListPager(Model, page => Url.Action("Index", "Category", new { page = page }))
    </div>

有人能指出我缺少的东西吗?任何帮助赞赏。

1 个答案:

答案 0 :(得分:0)

@using PagedList.Mvc;
@using PagedList;

@model IPagedList<Categories.CategoryListDto>
@Html.Editor("Search", ViewBag.searchItem as string, new { htmlAttributes = new { @class = "form-control", placeholder = "", maxlength = 50 } })
@Html.PagedListPager(Model, page => Url.Action("Index", "Category", new { searchItem = ViewBag.searchItem ,page = page }))
</div>