Nuget MVC PagedList Page Links not working correctly

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

I have a simple ViewModel that I want to display as a list page. I followed this tutorial for paging my list page. Heere is my controller code that returns a view with IPagedList

public ViewResult Index(int? page) {     List<ProjectViewModel> projectList = new List<ProjectViewModel>();     foreach (Project project in db.Projects)     {         projectList.Add(ProjectViewModel.ConvertToProjectViewModel(project));     }     var pageNumber = page ?? 1;     return View(projectList.ToPagedList(pageNumber, 3)); } 

Below is my view, that renders correctly with the pager rendering as well:

@using PagedList.Mvc; @using PagedList; @model PagedList.IPagedList<LayoutTest.ViewModels.ProjectViewModel>  <link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />  <script> $(function() {   $("div.progressbar2").progressbar({ value: 92 });   $("div.progressbar").each(function () {       var element = this;       $(element).progressbar({           value: parseInt($(element).attr("data-last-value")),       });   }); }); </script> @foreach (var item in Model) {    <div class="list-container">     <div class="list-image">         <img src="@item.ProjectLogo" width="300" height="225"/>     </div>     <div class="list-title">         @Html.DisplayFor(modelItem => item.Title)     </div>     <div class="list-min-container">         <div class="list-min-left">             Owner: TBD         </div>         <div class="list-min-right">             Cost: $@Html.DisplayFor(modelItem => item.EstimatedCost)         </div>     </div>     <div class="list-brief">         @Html.DisplayFor(modelItem => item.Brief)     </div>     <div class="list-min-container">         <div class="list-min-left">                         Location - TBD         </div>         <div class="list-min-right">             @Html.DisplayFor(modelItem => item.EndDate)         </div>     </div>     <div class="progressbar" data-last-value="@item.StartDate.Date.Month">         <div class="progress-label">@item.StartDate.Date.Month % complete</div>     </div>  </div> }  @Html.PagedListPager( (IPagedList)Model, page => Url.Action("Index", new { page }) ) 

However when I click on the pager to navigate to another page nothing happens, no error message or anything. Has anybody faced something similar?

EDIT :

Following is the html output from the PagedListPager:

 <div class="pagination PagedList-pager">  <ul><li class="previous disabled PagedList-skipToPrevious"><a>&larr; Previous</a></li>      <li class="active"><a>1</a></li>      <li><a href="/Project?Page=1">2</a></li>      <li class="next PagedList-skipToNext"><a href="/Project?Page=1">Next &rarr;</a></li>  </ul></div> 

回答1:

I used clientside debugging with Chrome and found that there was a javascript function that was disabling all anchors (PreventDefault). As List implements IEnumerable the datasource was fine. Now the Paging is working as expected. The code has always been fine. In case it may help anyone.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!