当我尝试在控制器中实现PagedList时,我一直遇到这个错误。确切的错误信息如下:
'DataIntelligence.Models.Execution'不包含'ToPagedList'的定义,也没有接受类型为'DataIntelligence.Models.Execution'的第一个参数的扩展方法'ToPagedList'被找到(您是否缺少使用指令或程序集引用?)。
我不知道为什么会出现这种情况。我已经查看了类似的问题,但似乎找不到我要找的答案。请问是否有人可以帮忙解决?
控制器:
'DataIntelligence.Models.Execution'不包含'ToPagedList'的定义,也没有接受类型为'DataIntelligence.Models.Execution'的第一个参数的扩展方法'ToPagedList'被找到(您是否缺少使用指令或程序集引用?)。
我不知道为什么会出现这种情况。我已经查看了类似的问题,但似乎找不到我要找的答案。请问是否有人可以帮忙解决?
控制器:
using DataIntelligence.Models;
using PagedList;
using PagedList.Mvc;
using System;
using System.Linq;
using System.Web.Mvc;
public ActionResult Execution(int? page, int id = 0)
{
var execution = db.Executions.Find(id);
if (execution == null)
{
return HttpNotFound();
}
ViewBag.ExecutionSeconds = (execution.End - execution.Start).ToString(@"dd\.hh\:mm\:ss\.fff");
int pageSize = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["DefaultPageSize"]);
int pageNumber = (page ?? 1);
return View(execution.ToPagedList(pageNumber, pageSize));
}
Execution Model
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace DataIntelligence.Models
{
[Table("Execution")]
public class Execution
{
public int Id { get; set; }
public Int16 PackageId { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public Boolean Successful { get; set; }
public virtual ICollection<Step> Steps { get; set; }
}
}
View
@model PagedList.IPagedList<DataIntelligence.Models.Execution>
@using PagedList.Mvc;
<link href="Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Execution Details";
}
<script language="javascript" type="text/javascript" src="jquery-1.8.3.js"> </script>
<script>
function goBack() {
window.history.back();
}
</script>
<div class="jumbotron">
<h2>Execution Details</h2>
</div>
<fieldset>
<legend>Execution Id - @Html.DisplayFor(model => model.Id)</legend>
<div class="row">
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.PackageId)
</div>
<div class="display-field">
<a href="@Url.Action("Package", new { id=Model.PackageId})"> @Html.DisplayFor(model => model.PackageId) </a>
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.Start)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Start)
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.End)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.End)
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
Execution Time
</div>
<div class="display-field">
@ViewBag.ExecutionSeconds
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.Successful)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Successful)
</div>
</div>
</div>
<br />
</fieldset>
<table>
<tr>
<th>
Step ID
</th>
<th id="stepname">
Name
</th>
<th id="stepdate">
Date
</th>
</tr>
@foreach (var step in Model.Steps) {
<tr>
<td>
@Html.DisplayFor(modelItem => step.Id)
</td>
<td id="steps">
@Html.DisplayFor(modelItem => step.Name)
</td>
<td id="date">
@Html.DisplayFor(modelItem => step.Date)
</td>
</tr>
}
</table>
<button class="btn btn-link" onclick="goBack()" style="padding-right: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px;">Back</button>
Page @(Model.Steps.PageCount < Model.Steps.PageNumber ? 0 : Model.Steps.PageNumber) of @Model.Steps.PageCount
@Html.PagedListPager(Model.Steps, page => Url.Action("Execution", new { page, sortOrder = ViewBag.CurrentSort}))
ToPagedList
应用于Execution
类的单个实例,你期望它做什么?它需要在IEnumerable
上。 - DavidG