創(chuàng)建Controller控件器與強(qiáng)類型視圖呢,還有Models里面的對(duì)象實(shí)體,相信你們看了我之前發(fā)的就能創(chuàng)建好了,在這里呢就不創(chuàng)建了哈親
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、網(wǎng)站建設(shè)、六合網(wǎng)絡(luò)推廣、小程序制作、六合網(wǎng)絡(luò)營(yíng)銷、六合企業(yè)策劃、六合品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供六合建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
在用戶控件器里面寫代碼了
下面這個(gè)分頁(yè)的方法
- ///
- /// 用戶信息分頁(yè)
- ///
- ///
- public ActionResult UserDataPage()
- {
- EFFristModelEntities ef = new EFFristModelEntities();
- int pageIndex = 1;//記錄頁(yè)的條數(shù)
- int pageSize = 3;//每頁(yè)顯示的條數(shù)
- int.TryParse(Request.QueryString["pageIndex"],out pageIndex);//強(qiáng)轉(zhuǎn)一下這個(gè)記錄頁(yè)的條數(shù)
- int pageIndexCount =Convert.ToInt32(ef.UserInfo.Count());//獲取 總的記錄數(shù)
- int pageCount = Convert.ToInt32(Math.Ceiling(pageIndexCount*1.0/pageSize));//獲取總的頁(yè)數(shù)
- //判斷頁(yè)的取值范圍
- if (pageIndex < 1)
- {
- pageIndex = 1;
- }
- if (pageIndex > pageCount)
- {
- pageIndex = pageCount;
- }
- //Linq語(yǔ)句
- var temp = from user in ef.UserInfo
- .OrderBy(user => user.ID)
- .Skip((pageIndex - 1) * pageSize)//跳過(guò)的序列
- .Take(pageSize)//返回指定數(shù)量的元素
- select user;
- ViewData.Model = temp;//把這個(gè)Linq語(yǔ)句讀取的數(shù)據(jù)給這個(gè)實(shí)體model
- ViewData["pageIndex"] = pageIndex;
- ViewData["pageIndexCount"] = pageIndexCount;
- ViewData["pageCount"] = pageCount;
- ViewData["pageSize"] = pageSize;
- return View();
- }
這個(gè)在前臺(tái)循環(huán)的展示數(shù)據(jù)
- <%for (int i = 1; i <= Convert.ToInt32(ViewData["pageCount"]); i++)
- { %>
- <%:Html.ActionLink(i.ToString(),"UserDataPage",new {pageIndex=i}) %>
- <%} %>
- <%:"當(dāng)前頁(yè):" + ViewData["pageSize"] + "數(shù)據(jù)"%> <%:"共:"+ViewData["pageIndexCount"]+"條" %> <%:"共:"+ViewData["pageCount"]+"頁(yè)" %>
第二種分頁(yè) 有樣式
這個(gè)是在models里面創(chuàng)建的類 是一個(gè)靜態(tài)的類型為HtmlString的 是微軟定義的一個(gè)類
- public static HtmlString ShowPageNavigate(this HtmlHelper htmlHelper, int currentPage, int pageSize, int totalCount)
- {
- var redirectTo = htmlHelper.ViewContext.RequestContext.HttpContext.Request.Url.AbsolutePath;
- pageSize = pageSize == 0 ? 3 : pageSize;
- var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //總頁(yè)數(shù)
- var output = new StringBuilder();
- if (totalPages > 1)
- {
- //if (currentPage != 1)
- {//處理首頁(yè)連接
- output.AppendFormat("首頁(yè) ", redirectTo, pageSize);
- }
- if (currentPage > 1)
- {//處理上一頁(yè)的連接
- output.AppendFormat("上一頁(yè) ", redirectTo, currentPage - 1, pageSize);
- }
- else
- {
- // output.Append("上一頁(yè)");
- }
- output.Append(" ");
- int currint = 5;
- for (int i = 0; i <= 10; i++)
- {//一共最多顯示10個(gè)頁(yè)碼,前面5個(gè),后面5個(gè)
- if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
- {
- if (currint == i)
- {//當(dāng)前頁(yè)處理
- //output.Append(string.Format("[{0}]", currentPage));
- output.AppendFormat("{3} ", redirectTo, currentPage, pageSize, currentPage);
- }
- else
- {//一般頁(yè)處理
- output.AppendFormat("{3} ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint);
- }
- }
- output.Append(" ");
- }
- if (currentPage < totalPages)
- {//處理下一頁(yè)的鏈接
- output.AppendFormat("下一頁(yè) ", redirectTo, currentPage + 1, pageSize);
- }
- else
- {
- //output.Append("下一頁(yè)");
- }
- output.Append(" ");
- if (currentPage != totalPages)
- {
- output.AppendFormat("末頁(yè) ", redirectTo, totalPages, pageSize);
- }
- output.Append(" ");
- }
- output.AppendFormat("第{0}頁(yè) / 共{1}頁(yè)", currentPage, totalPages);//這個(gè)統(tǒng)計(jì)加不加都行
- return new HtmlString(output.ToString());
- }
- 在前臺(tái)調(diào)用這個(gè)方法即可
- <%:Html.ShowPageNavigate(Convert.ToInt32(ViewData["pageIndex"]),3,Convert.ToInt32(ViewData["pageCount"])) %>
這個(gè)是樣式文件夾 這個(gè)呢可以在網(wǎng)上扒的哈,我這不一定你就能用的哦 親
- .paginator
- {
- font: 12px Arial, Helvetica, sans-serif;
- padding: 10px 20px 10px 0;
- margin: 0px;
- }
- .paginator a
- {
- border: solid 1px #ccc;
- color: #0063dc;
- cursor: pointer;
- text-decoration: none;
- }
- .paginator a:visited
- {
- padding: 1px 6px;
- border: solid 1px #ddd;
- background: #fff;
- text-decoration: none;
- }
- .paginator .cpb
- {
- border: 1px solid #F50;
- font-weight: 700;
- color: #F50;
- background-color: #ffeee5;
- }
- .paginator a:hover
- {
- border: solid 1px #F50;
- color: #f60;
- text-decoration: none;
- }
- .paginator a, .paginator a:visited, .paginator .cpb, .paginator a:hover
- {
- float: left;
- height: 16px;
- line-height: 16px;
- min-width: 10px;
- _width: 10px;
- margin-right: 5px;
- text-align: center;
- white-space: nowrap;
- font-size: 12px;
- font-family: Arial,SimSun;
- padding: 0 3px;
- }
- /*****************************2*/
- .page_nav,
- #commentpage{clear:both; padding:15px 0; color:#666; font:normal 12px/24px Arial; text-align:center;}
- .page_nav a,
- #commentpage a{display:inline-block; height:22px; margin:0 2px; padding:0 8px; border:solid 1px #dbe5ee; -moz-border-radius:2px; -webkit-border-radius:2px; -khtml-border-radius:2px; border-radius:2px; background:#fff; color:#333; font:normal 12px/22px Arial, Helvetica, sans-serif; cursor:pointer;}
- .page_nav strong{display:inline-block; height:24px; margin:0 3px; padding:0 8px; border:none; -moz-border-radius:2px; -webkit-border-radius:2px; -khtml-border-radius:2px; border-radius:2px; background:#c00; color:#fff; font-weight:normal; line-height:24px; text-decoration:none;}
- .page_nav a:hover,
- .page_nav a.on{height:24px; margin:0 3px; border:none; background:#c00; color:#fff; line-height:24px; text-decoration:none;}
- .page_nav a.select{cursor:default;}
- .page_nav .view_all{display:block; text-align:center;}
- .page_nav .view_all a{height:auto; margin:0; padding:0; border:none; color:#06c; line-height:24px;}
- .page_nav .view_all a:hover{height:auto; margin:0; padding:0; background:none;}