0
我使用DotLiquid模板引擎来允许在应用程序中进行主题化。Dot Liquid中的访问集合属性
其中,我有一个分段列表继承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 }} |
这是替换
|
任何人都可以看到,我错了?
谢谢蒂姆,看起来就是这样。 – EverythingGeek