我有一个采用 PaginatedList 的视图(例如在 Nerd Dinner 示例中)。该页面按预期工作。现在我添加了一个采用相同 PaginatedList 的局部视图,并在第一个视图中调用 RnederPartial。ASP.NET 引发了一个我似乎无法解决的异常。
分页列表代码:
public class PaginatedList<T> : List<T>
{
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; }
public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
}
public bool HasPreviousPage
{
get
{
return (PageIndex > 0);
}
}
public bool HasNextPage
{
get
{
return (PageIndex + 1 < TotalPages);
}
}
}
控制器:
[Authorize]
public ActionResult Index(int? page)
{
const int pageSize = 10;
var workstations = itilRepository.FindAllWorkstations();
var paginatedWorkstations = new PaginatedList<Workstation>(workstations, page ?? 0, pageSize);
return View("Index", paginatedWorkstations);
}
索引视图顶部:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ITILDatabase.Helpers.PaginatedList<ITILDatabase.Models.Workstation>>" %>
我在 Index 视图中调用局部视图如下:
<% Html.RenderPartial("Workstations", Model); %>
工作站顶部局部视图:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewPage<ITILDatabase.Helpers.PaginatedList<ITILDatabase.Models.Workstation>>" %>
我收到的错误是:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\d2889d23\c6192b3e\App_Web_workstations.ascx.a8d08dba.tgrd74s0.0.cs(156):错误 CS0030:无法转换类型 'ASP .views_home_workstations_ascx' 到 'System.Web.Mvc.ViewUserControl'
如果有人知道我为什么会收到此错误,我将不胜感激。
谢谢你!