【发布时间】:2012-06-07 21:29:20
【问题描述】:
我正在尝试将 PagedList 对象 (https://github.com/martijnboland/MvcPaging/blob/master/src/MvcPaging/PagedList.cs) 序列化为 Json,如下所示:
PagedList<Product> pagedList = new PagedList<Product>(products, (page - 1), pageSize);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(pagedList);
如果我使用上面的代码,我会得到一个正确序列化的 Product 对象数组。但是(PagedList)下面的属性不包含在 Json 结果中:
public bool HasNextPage { get; }
public bool HasPreviousPage { get; }
public bool IsFirstPage { get; }
public bool IsLastPage { get; }
public int ItemEnd { get; }
public int ItemStart { get; }
public int PageCount { get; }
public int PageIndex { get; }
public int PageNumber { get; }
public int PageSize { get; }
public int TotalItemCount { get; }
它们没有被序列化,但它们是 PagedList 的一部分。
有人知道为什么吗?我怎样才能在序列化中包含这些属性?
谢谢
【问题讨论】: