方法-:
1,在Service中使用pagedlist实现翻页的方法
写法一:
/// <summary>
/// 政策法规的more列表翻页
/// </summary>
/// <param name="page">分页的页码</param>
/// <param name="sid">部门代码</param>
/// <returns></returns>
public PagedList<C_Newss> Lists(int? page)
{
Expression<Func<C_Newss, bool>> filter = t => true;
int pageSize = 10;//每页显示的数量
filter = filter.And(t => t.News_kind ==171);
using (JY_VillageEntities db = new JY_VillageEntities())
{
return db.C_Newss.Where(filter).OrderByDescending(t=>t.pub_date).ToPagedList(page ?? 1, pageSize);
}
}
写法二:
public PagedList<P_Finances> GetPagedListByDWDM(string dwdm, int? page)
{
int pageSize = 10;
using (JY_VillageEntities db = new JY_VillageEntities())
{
return db.P_Finances.Where(item => item.DWDM == dwdm).OrderByDescending(item => item.Year).ThenByDescending(item => item.Month).ToPagedList(page ?? 1, pageSize);
}
}
2,在ACTION中调用翻页的方法
/// <summary>
/// 政策法规more列表数据
/// </summary>
/// <param name="ClassNo"></param>
/// <param name="sid"></param>
/// <returns></returns>
public ActionResult List(int? page, int? sid)
{
//ViewData.Model = homeService.MoreList(ClassNo, sid);
ViewData.Model = homeService.Lists(page);
return View();
}
3,在View中的使用
@using Webdiyer.WebControls.Mvc
@model Webdiyer.WebControls.Mvc.PagedList<Community.Site.Models.C_Newss>
<div id="pageContent">
<ul>
foreach (var item in Model)
{
<li><a href="@Url.Action("News", new { NewsNo = item.ID })"><span>@(item.CreateOn)</span>@(item.Title)</a></li>
}
}
</ul>
</div>
使用MvcPager插件可以直接用@Html.Pager这个控件
@* @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "page", CssClass = "Pagination"})*@
使用自己写的按钮用下面的
<div class="page">
<span class="pageLeft"><a href="@Url.Action("List", new { page = Model.CurrentPageIndex == 1 ? "" : (Model.CurrentPageIndex - 1).ToString() })">
</a></span><span class="pageNum">@Model.CurrentPageIndex / @Model.TotalPageCount</span>
<span class="pageRight"><a href="@Url.Action("List", new { page =(Model.CurrentPageIndex + 1) })"></a></span>
</div>
asp.net mvc 使用MvcPager实现翻页功能,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/yushuo/p/3798647.html