我正在使用 DotLiquid 模板引擎来允许在应用程序中进行主题化。
在其中,我有一个从 List 继承的分页列表,该列表已注册为安全类型,允许访问其中的成员。PaginatedList 来自应用程序中的更高层,并且不知道正在使用 Dot Liquid 的事实,因此使用 RegisterSafeType 而不是继承 Drop。
Template.RegisterSafeType(typeof(PaginatedList<>), new string[] {
"CurrentPage",
"HasNextPage",
"HasPreviousPage",
"PageSize",
"TotalCount",
"TotalPages"
});
public class PaginatedList<T> : List<T>
{
/// <summary>
/// Returns a value representing the current page being viewed
/// </summary>
public int CurrentPage { get; private set; }
/// <summary>
/// Returns a value representing the number of items being viewed per page
/// </summary>
public int PageSize { get; private set; }
/// <summary>
/// Returns a value representing the total number of items that can be viewed across the paging
/// </summary>
public int TotalCount { get; private set; }
/// <summary>
/// Returns a value representing the total number of viewable pages
/// </summary>
public int TotalPages { get; private set; }
/// <summary>
/// Creates a new list object that allows datasets to be seperated into pages
/// </summary>
public PaginatedList(IQueryable<T> source, int currentPage = 1, int pageSize = 15)
{
CurrentPage = currentPage;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
AddRange(source.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList());
}
/// <summary>
/// Returns a value representing if the current collection has a previous page
/// </summary>
public bool HasPreviousPage
{
get
{
return (CurrentPage > 1);
}
}
/// <summary>
/// Returns a value representing if the current collection has a next page
/// </summary>
public bool HasNextPage
{
get
{
return (CurrentPage < TotalPages);
}
}
}
然后将此列表暴露给 local.Products 中的视图,在 Dot Liquid 中迭代集合可以正常工作。
但是,我正在尝试访问其中的属性,我没有收到任何错误,但没有值被 Dot Liquid 替换。
我在用
{{ local.Products.CurrentPage }} |
替换为
|
谁能看到我哪里出错了?