2

我正在使用 MVC 5 和 PagedList.MVC 4.5.0.0,我有数据返回并显示在我的表上,同时显示了寻呼机控件。当我单击下一步时,寻呼机继续将 page = 1 发送到我的函数,在调试时看到。

我的页面有:

                <div class="pagedList" data-otf-target="#contractList">
                @Html.PagedListPager(Model, page => Url.Action("Index", new { page }), PagedListRenderOptions.MinimalWithItemCountText)
            </div>

我将数据发送回操作的方法是

        public IPagedList<ContractViewModel> GetAllContracts(int page = 1)
    {
        var lstcontractViewModel = new List<ContractViewModel>();
        using (ContractRepository contractRepos = new ContractRepository(new UnitOfWork()))
        {
            var activeContractList = contractRepos.All.OrderByDescending(x => x.Id);

            foreach (var activeContract in activeContractList)
            {
                Mapper.CreateMap<DomainClasses.ActiveContract, ActiveContractViewModel>().ForMember(dest => dest.ContractorModel, opts => opts.Ignore());

                Mapper.AssertConfigurationIsValid();
                lstcontractViewModel.Add(Mapper.Map<ActiveContractViewModel>(activeContract));
            }
        }

        return lstcontractViewModel.ToPagedList(page, 40);
    }

我的控制器的动作是

        public ActionResult Index()
    {
        var contracts = activeaccountController.GetAllContracts(); 
        return View(contracts);
    }

正如我所说,第一页一切正常,就在调用 GetAllContracts 方法时,调试器显示页面始终为 = 1。因此分页始终只返回结果的第一页。我有超过 2500 条记录,所以还有其他数据,因为寻呼机也显示,寻呼机说“显示 2546 的项目 1 到 40”。

4

1 回答 1

1
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), PagedListRenderOptions.MinimalWithItemCountText)

尝试设置 new{page = somevalue} 它将发送一个参数。

Public ActionResult Index(int page) 

public IPagedList<ContractViewModel> GetAllContracts(int page = 1)

这意味着如果没有应用其他参数,则页面默认为 1。

var contracts = activeaccountController.GetAllContracts(page); 

有关更多信息,请阅读https://github.com/TroyGoode/PagedList

于 2014-04-22T19:55:19.143 回答