在所有配置都可以的情况下,PagedListPager()方法不起作用

时间:2018-10-29 07:08:13

标签: c# asp.net-mvc pagination

我有一个简单的分页视图,如下所示:

@using PagedList;
@using PagedList.Mvc;
@model PagedList.IPagedList<PgcbSms.Core.Entities.SmsLog>

@{
    ViewData["Title"] = "SMSLog";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>SMSLog</h2>

<table class="table table-striped">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.First().originator)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().content)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().messageDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().receivedDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().dbinsertdate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.First().status)
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.originator)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.content)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.messageDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.receivedDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.dbinsertdate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.status)
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.PagedListPager(Model, page => Url.Action("SMSLog", new { page}))

但是我遇到以下错误:

enter image description here

我添加两行:

@using PagedList;
@using PagedList.Mvc;

,并研究asp.net mvc中的分页代码,但是我的代码中没有遗漏任何内容。那么,为什么我会收到这样的错误?任何想法?谢谢您的时间。

更新: 控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PgcbSms.Core.Entities;
using PgcbSms.Services.SmsLogServices;
using PagedList;
using PagedList.Mvc;

namespace PgcgSms.WebSite.Controllers
{
    public class ReportsController : Controller
    {
        private ISmsLogService _smsLogService;
        public ReportsController(ISmsLogService smsLogService)
        {
            _smsLogService = smsLogService;
        }
        public IActionResult SMSLog(int? page)
        {
            IPagedList<SmsLog> smsLogs = _smsLogService.GetSmsLogsPaged(page);
            return View(smsLogs);
        }
    }
}

Update2:

 public IPagedList<SmsLog> GetSmsLogsPaged(int? page)
        {
            return _smsRepository.Table.ToList().ToPagedList(page ?? 1, 10);
        }

0 个答案:

没有答案