我不会对其进行分页,而是做一些事情来显示部分数据并更新视图。
你还没有说为什么,所以我会假设在大多数情况下不会发送比对用户有用的更多的数据。
假设:一个类 类似于:
public class ContentView
{
public int Id {get; set;}
public string Content {get; set; }
public DateTime LastEditedTime { get; set; }
}
你可以查询(我心血来潮的伪代码):
dbContext.Books.Join(EditHistory, b => b.Id, e => e.BookId, (b,e) => new {b, e})
.Select(new ContentView() {Id = b.Id,
content = b.Exceprt.Substring(0, Math.Min(b.Exceprt.Length, 100)),
LastEditedTime = e.ModifiedTime}).ToList();
所以这里的字符串是 100 个字符。
然后在视图中有一个通过按钮(例如放大镜或椭圆)调用的方法,该方法使用 ID 调用 API/数据库并返回全文。
如果你必须分页:
将string content 替换为类似于:
public class Content
{
public int Page { get; set; }
public string BookText { get; set; }
}
然后每次单击按钮时,查询都可以获取更多数据并追加:
return db.Books.Where(w => w.Id == id)
.Select(s => new Content() {
BookText = s.Passage.substring(page * 100, page + 1 * 100),
Page = page++ );
或从0到当前页码*每页字符数的类似子字符串并替换现有内容。