C# asp.net mvc类blogger中的分页
我喜欢在我的asp.NETMVC(C#)应用程序中实现分页,就像blogger(blogspot.com)中的一样 分页应该如下所示:C# asp.net mvc类blogger中的分页,c#,asp.net-mvc,pagination,custompaging,C#,Asp.net Mvc,Pagination,Custompaging,我喜欢在我的asp.NETMVC(C#)应用程序中实现分页,就像blogger(blogspot.com)中的一样 分页应该如下所示: `New Posts Home Older Posts` 页面应包含可配置的项目数 有什么想法吗?这不完全是你想要的,但你可以想出来 最简单的方法是在控制器中查找下一篇和上一篇文章/博客,然后使用ViewData将它们传递到视图中,即 ViewData["NextPost"]
`New Posts Home Older Posts`
页面应包含可配置的项目数
有什么想法吗?这不完全是你想要的,但你可以想出来
最简单的方法是在控制器中查找下一篇和上一篇文章/博客,然后使用ViewData将它们传递到视图中,即
ViewData["NextPost"] = Model.GetNextPost();
ViewData["PrevPost"] = Model.GetPrevPost();
然后只需在视图中显示以下内容:
<ul>
<li><%= Html.Action("New posts", new { Action = "View", Id = (Post)ViewData["NextPost"].Id }) %></li>
<li><%= Html.Action("Home", new { Action = "Home" }) %></li>
<li><%= Html.Action("Old posts", new { Action = "View", Id = (Post)ViewData["PrevPost"].Id }) %></li>
</ul>
你将需要样式的ul,使它看起来漂亮。如果您想使这段代码可重用,可以将显示代码放在局部视图中。您已经看过nerddinner示例应用程序了吗?他们实现了分页。它在url中显示querystring,我不想这样显示。