(菜鸟要飞系列)五,基于Asp.Net MVC5的后台管理系统(添加数据表的分页功能)

献上代码

 1 public ActionResult SelectAll(int id=1)
 2         {
 3             
 4             List<UserModel> arrayUserModel = new List<UserModel>();
 5             string strText = Request.Form["find"];  //接参
 6             OracleHelper ora = new OracleHelper();
 7             string sql = "select * from tbuser where displayname like'%" + strText + "%'";
 8             DataTable dt = ora.Connect(sql);
 9             for (int i = 0; i < dt.Rows.Count; i++)
10             {
11                 UserModel userModel = new UserModel();
12                 userModel.UserId = dt.Rows[i][0].ToString();
13                 userModel.UserName = dt.Rows[i][2].ToString();
14                 userModel.Sex = dt.Rows[i][1].ToString();
15                 userModel.DisplayName = dt.Rows[i][3].ToString();
16                 userModel.Protrait = dt.Rows[i][4].ToString();
17                 userModel.Authority = Convert.ToInt32(dt.Rows[i][5]);
18                 userModel.Place = dt.Rows[i][6].ToString();
19                 userModel.JinFen = Convert.ToInt32(dt.Rows[i][7]);
20                 userModel.UserPassword = dt.Rows[i][8].ToString();
21                 arrayUserModel.Add(userModel);
22             }
23             var model = arrayUserModel.OrderBy(a => a.UserId).ToPagedList(id, 10);
24             if (Request.IsAjaxRequest())
25                 return PartialView("SelectAll", model);
26             return View(model);
27         }

添加引用 是杨涛老师的Asp.Net开源世界下载的

关键代码是

  1 @using Webdiyer.WebControls.Mvc;
  2 @model PagedList<MatrixAdmin.Areas.Member.Models.UserModel>
  3 
  4 <style type="text/css">
  5     .pagination {
  6   display: inline-block;
  7   padding-left: 0;
  8   margin: 20px 0;
  9   border-radius: 4px;
 10 }
 11 .pagination > li {
 12   display: inline;
 13 }
 14 .pagination > li > a,
 15 .pagination > li > span {
 16   position: relative;
 17   float: left;
 18   padding: 6px 12px;
 19   margin-left: -1px;
 20   line-height: 1.42857143;
 21   color: #337ab7;
 22   text-decoration: none;
 23   background-color: #fff;
 24   border: 1px solid #ddd;
 25 }
 26 .pagination > li:first-child > a,
 27 .pagination > li:first-child > span {
 28   margin-left: 0;
 29   border-top-left-radius: 4px;
 30   border-bottom-left-radius: 4px;
 31 }
 32 .pagination > li:last-child > a,
 33 .pagination > li:last-child > span {
 34   border-top-right-radius: 4px;
 35   border-bottom-right-radius: 4px;
 36 }
 37 .pagination > li > a:hover,
 38 .pagination > li > span:hover,
 39 .pagination > li > a:focus,
 40 .pagination > li > span:focus {
 41   color: #23527c;
 42   background-color: #eee;
 43   border-color: #ddd;
 44 }
 45 .pagination > .active > a,
 46 .pagination > .active > span,
 47 .pagination > .active > a:hover,
 48 .pagination > .active > span:hover,
 49 .pagination > .active > a:focus,
 50 .pagination > .active > span:focus {
 51   z-index: 2;
 52   color: #fff;
 53   cursor: default;
 54   background-color: #337ab7;
 55   border-color: #337ab7;
 56 }
 57 .pagination > .disabled > span,
 58 .pagination > .disabled > span:hover,
 59 .pagination > .disabled > span:focus,
 60 .pagination > .disabled > a,
 61 .pagination > .disabled > a:hover,
 62 .pagination > .disabled > a:focus {
 63   color: #777;
 64   cursor: not-allowed;
 65   background-color: #fff;
 66   border-color: #ddd;
 67 }
 68 .pagination-lg > li > a,
 69 .pagination-lg > li > span {
 70   padding: 10px 16px;
 71   font-size: 18px;
 72 }
 73 .pagination-lg > li:first-child > a,
 74 .pagination-lg > li:first-child > span {
 75   border-top-left-radius: 6px;
 76   border-bottom-left-radius: 6px;
 77 }
 78 .pagination-lg > li:last-child > a,
 79 .pagination-lg > li:last-child > span {
 80   border-top-right-radius: 6px;
 81   border-bottom-right-radius: 6px;
 82 }
 83 .pagination-sm > li > a,
 84 .pagination-sm > li > span {
 85   padding: 5px 10px;
 86   font-size: 12px;
 87 }
 88 .pagination-sm > li:first-child > a,
 89 .pagination-sm > li:first-child > span {
 90   border-top-left-radius: 3px;
 91   border-bottom-left-radius: 3px;
 92 }
 93 .pagination-sm > li:last-child > a,
 94 .pagination-sm > li:last-child > span {
 95   border-top-right-radius: 3px;
 96   border-bottom-right-radius: 3px;
 97 }
 98 </style>
 99 
100 <div class="row">
101     <div class="col-md-9">
102         @Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id", NumericPagerItemCount = 8, ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>", DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>", PagerItemTemplate = "<li>{0}</li>", PageIndexBoxId = "pageIndexBox", GoToButtonId = "goToBtn" }).AjaxOptions(a => a.SetUpdateTargetId("id"))
103     </div>
104 </div>

数据库可以自己定义,,你们也可以直接去看杨涛老师自己写的例子,十分强大,图示如下

posted @ 2016-04-23 22:37  爱嘴硬的咚咚酱  阅读(585)  评论(0编辑  收藏  举报