創(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è)策劃、六合品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供六合建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:muchs.cn
在用戶控件器里面寫代碼了
下面這個(gè)分頁的方法
- /// <summary>
- /// 用戶信息分頁
- /// </summary>
- /// <returns></returns>
- public ActionResult UserDataPage()
- {
- EFFristModelEntities ef = new EFFristModelEntities();
- int pageIndex = 1;//記錄頁的條數(shù)
- int pageSize = 3;//每頁顯示的條數(shù)
- int.TryParse(Request.QueryString["pageIndex"],out pageIndex);//強(qiáng)轉(zhuǎn)一下這個(gè)記錄頁的條數(shù)
- int pageIndexCount =Convert.ToInt32(ef.UserInfo.Count());//獲取 總的記錄數(shù)
- int pageCount = Convert.ToInt32(Math.Ceiling(pageIndexCount*1.0/pageSize));//獲取總的頁數(shù)
- //判斷頁的取值范圍
- if (pageIndex < 1)
- {
- pageIndex = 1;
- }
- if (pageIndex > pageCount)
- {
- pageIndex = pageCount;
- }
- //Linq語句
- var temp = from user in ef.UserInfo
- .OrderBy(user => user.ID)
- .Skip((pageIndex - 1) * pageSize)//跳過的序列
- .Take(pageSize)//返回指定數(shù)量的元素
- select user;
- ViewData.Model = temp;//把這個(gè)Linq語句讀取的數(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}) %><!--這用到了Html.ActionLink鏈接標(biāo)簽里面的參數(shù)有一個(gè)文本鏈接就是所得到的數(shù)字,第二個(gè)參數(shù)為執(zhí)行的方法,第三個(gè)是值-->
- <%} %>
- <%:"當(dāng)前頁:" + ViewData["pageSize"] + "數(shù)據(jù)"%> <%:"共:"+ViewData["pageIndexCount"]+"條" %> <%:"共:"+ViewData["pageCount"]+"頁" %>
第二種分頁 有樣式
這個(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); //總頁數(shù)
- var output = new StringBuilder();
- if (totalPages > 1)
- {
- //if (currentPage != 1)
- {//處理首頁連接
- output.AppendFormat("<a class='pageLink' href='{0}?pageIndex=1&pageSize={1}'>首頁</a> ", redirectTo, pageSize);
- }
- if (currentPage > 1)
- {//處理上一頁的連接
- output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>上一頁</a> ", redirectTo, currentPage - 1, pageSize);
- }
- else
- {
- // output.Append("<span class='pageLink'>上一頁</span>");
- }
- output.Append(" ");
- int currint = 5;
- for (int i = 0; i <= 10; i++)
- {//一共最多顯示10個(gè)頁碼,前面5個(gè),后面5個(gè)
- if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
- {
- if (currint == i)
- {//當(dāng)前頁處理
- //output.Append(string.Format("[{0}]", currentPage));
- output.AppendFormat("<a class='cpb' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage, pageSize, currentPage);
- }
- else
- {//一般頁處理
- output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint);
- }
- }
- output.Append(" ");
- }
- if (currentPage < totalPages)
- {//處理下一頁的鏈接
- output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>下一頁</a> ", redirectTo, currentPage + 1, pageSize);
- }
- else
- {
- //output.Append("<span class='pageLink'>下一頁</span>");
- }
- output.Append(" ");
- if (currentPage != totalPages)
- {
- output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>末頁</a> ", redirectTo, totalPages, pageSize);
- }
- output.Append(" ");
- }
- output.AppendFormat("第{0}頁 / 共{1}頁", currentPage, totalPages);//這個(gè)統(tǒng)計(jì)加不加都行
- return new HtmlString(output.ToString());
- }
- 在前臺(tái)調(diào)用這個(gè)方法即可
- <div class="page_nav">
- <%:Html.ShowPageNavigate(Convert.ToInt32(ViewData["pageIndex"]),3,Convert.ToInt32(ViewData["pageCount"])) %>
- </div>
- <p>
這個(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;}
分享文章:MVC分頁讓你更爽
鏈接URL:http://muchs.cn/article10/gehogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站排名、小程序開發(fā)、手機(jī)網(wǎng)站建設(shè)、外貿(mào)建站、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)