ibcadmin 发表于 2013-8-17 10:43:27

MVC中分页控件-MvcPager

先去下载 mvcpage http://mvcpager.codeplex.com/releases/view/64098
转载博客园

只需要一个 MvcPager.dll文件即可 然后引用MvcPager.dllModels 引入命名空间
new { ID =ViewBag.ID } 这里放分页前的地址栏查询参数,没有可以不写


@using Webdiyer.WebControls.Mvc
@using MVC.Models
@using System.Data


<div class="pages" style="text-align:left; margin-left:20px; margin-top:20px; width:80%" > <table>
<tr>
<td>@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "currentPage", ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.DropDownList, ShowGoButton = false, PageIndexBoxWrapperFormatString = "跳转到{0}", FirstPageText = "首页",CssClass="pages" }, "default", new { ID =ViewBag.ID })
</td>
<td>共<span > @Model.TotalItemCount</span> 条记录,页 <span >@Model.CurrentPageIndex/@Model.TotalPageCount</span></td>
</tr>
</table> </div>
  



/*分页样式*/

?
.pages { color: #000000; }
.pages a { text-decoration:none; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages span
{
color:red;
}
  



controllers

mvcpager 集成了ToPagedList。使用之前必须使用排序 否则会报错,



?
private EFHelpDB db = new EFHelpDB();

public ActionResult Index(int id = 0, int currentPage = 1)
{

int pageSize = 10;//每页条数
ViewBag.ID = id;//分页之前的查询参数
return View(db.Me.Where(m => m.ParentID == id).OrderBy(m => m.Orderby).ToPagedList(currentPage, pageSize));

}

yuayuaaaa 发表于 2013-8-27 11:22:52

yuayuaaaa

冰果_C 发表于 2015-5-19 09:50:01

mark
页: [1]
查看完整版本: MVC中分页控件-MvcPager