简体   繁体   English

Nuget MVC PagedList页面链接无法正常工作

[英]Nuget MVC PagedList Page Links not working correctly

I have a simple ViewModel that I want to display as a list page. 我有一个想要显示为列表页面的简单ViewModel。 I followed this tutorial for paging my list page. 我按照教程分页列表页面。 Heere is my controller code that returns a view with IPagedList Heere是我的控制器代码,它返回带有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: 以下是PagedListPager的html输出:

 <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>

I used clientside debugging with Chrome and found that there was a javascript function that was disabling all anchors (PreventDefault). 我在Chrome上使用了客户端调试功能,发现有一个javascript函数禁用了所有锚点(PreventDefault)。 As List implements IEnumerable the datasource was fine. 由于List实现IEnumerable,因此数据源很好。 Now the Paging is working as expected. 现在分页正在按预期方式工作。 The code has always been fine. 该代码一直很好。 In case it may help anyone. 万一它可以帮助任何人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM