• <ul id="cgeq2"></ul>
  • 歡迎您光臨深圳塔燈網(wǎng)絡(luò)科技有限公司!
    電話圖標(biāo) 余先生:13699882642

    pageadmin模板中如何實(shí)現(xiàn)分頁

    發(fā)表日期:2019-04 文章編輯:小燈 瀏覽次數(shù):2862

    在信息頁中調(diào)用分頁數(shù)據(jù)時(shí),信息后面一般都需要分頁控制按鈕面板,分頁面板是一個(gè)稍顯繁瑣的功能,下面直接上代碼:

    @functions{
    ????//默認(rèn)分頁函數(shù)
    ????private?string?Pagebreak(int?page,?string?urlPrefix,?string?urlParams?=?"")
    ????{
    ????????string?rv?=?"";
    ????????if?(page?>?1)
    ????????{
    ????????????rv?=?urlPrefix?+?page?+?"/";
    ????????}
    ????????else
    ????????{
    ????????????rv?=?urlPrefix;
    ????????}
    ????????rv?+=?urlParams;
    ????????return?rv;
    ????}
    ????//獲取url參數(shù)方法
    ????private?string?GetUrlParams()
    ????{
    ????????string?rv?=?"";
    ????????System.Collections.Specialized.NameValueCollection?queryStrings?=?Request.QueryString;
    ????????int?count?=?queryStrings.Count;
    ????????if?(count?>?0)
    ????????{
    ????????????rv?=?"?";
    ????????}
    ????????foreach?(string?key?in?queryStrings)
    ????????{
    ????????????if?(rv.IndexOf("=")?>?0)
    ????????????{
    ????????????????rv?+=?"&";
    ????????????}
    ????????????rv?+=?key?+?"="?+?HttpUtility.UrlEncode(queryStrings[key]);
    ????????}
    ????????return?rv;
    ????}
    }
    @{
    ????PageInfo?pageInfo?=?(PageInfo)Model;
    ????int?pageCount?=?pageInfo.PageCount;
    ????int?pageSize?=?pageInfo.PageSize;
    ????int?recordCount?=?pageInfo.RecordCount;
    ????int?currentPage?=?pageInfo.CurrentPage;
    ????int?m?=?2;?//左右兩邊顯示頁碼數(shù)
    ????string?urlParams?=?GetUrlParams();
    ????string?urlPrefix?=?Html.ColumnUrl();//獲取當(dāng)前欄目url,如果是自定義文件,請(qǐng)自行修改為路徑。
    }
    ????<div?class="text-center">
    ????????<ul?class="pagination">
    ????????????@{
    ????????????????if?(currentPage?>?1)
    ????????????????{
    ????????????????????<li>
    ????????????????????????<a?href="@Pagebreak(currentPage-1,urlPrefix,urlParams)">&laquo;</a>
    ????????????????????</li>
    ????????????????}
    ????????????????else
    ????????????????{
    ????????????????????<li?class="disabled">
    ????????????????????????<a>&laquo;</a>
    ????????????????????</li>
    ????????????????}
    ????????????????int?startPage?=?currentPage?-?m;
    ????????????????int?lastPage?=?currentPage?+?m;
    ????????????????int?cha?=?0;
    ????????????????if?(lastPage?>?pageCount)
    ????????????????{
    ????????????????????cha?=?lastPage?-?pageCount;
    ????????????????????startPage?=?startPage?-?cha;
    ????????????????????if?(startPage?<?1)
    ????????????????????{
    ????????????????????????startPage?=?1;
    ????????????????????}
    ????????????????????lastPage?=?pageCount;
    ????????????????}
    ????????????????else?if?(startPage?<?1)
    ????????????????{
    ????????????????????cha?=?1?-?startPage;
    ????????????????????startPage?=?startPage?+?cha;
    ????????????????????lastPage?=?lastPage?+?cha;
    ????????????????????if?(lastPage?>?pageCount)
    ????????????????????{
    ????????????????????????lastPage?=?pageCount;
    ????????????????????}
    ????????????????}
    ????????????????if?(startPage?>?1)
    ????????????????{
    ????????????????????<li><a?href="@Pagebreak(1,urlPrefix,urlParams)">1?...</a></li>
    ????????????????}
    ????????????????for?(int?i?=?startPage;?i?<=?lastPage;?i++)
    ????????????????{
    ????????????????????<li@(currentPage==i?"?class=active":"")><a?href="@Pagebreak(i,urlPrefix,urlParams)">@i</a></li>
    ????????????????}
    ????????????????if?(lastPage?<?pageCount)
    ????????????????{
    ????????????????????<li><a?href="@Pagebreak(pageCount,urlPrefix,urlParams)">...?@pageCount</a></li>
    ????????????????}
    ????????????????if?(currentPage?<?pageCount)
    ????????????????{
    ????????????????????<li>
    ????????????????????????<a?href="@Pagebreak(currentPage+1,urlPrefix,urlParams)">&raquo;</a>
    ????????????????????</li>
    ????????????????}
    ????????????????else
    ????????????????{
    ????????????????????<li?class="disabled">
    ????????????????????????<a>&raquo;</a>
    ????????????????????</li>
    ????????????????}
    ????????????}
    ????</ul>
    </div>

    把上面代碼保存為PagebreakPartial.cshtml放在模板的Views/Shared目錄下作為局部文件,這樣就可以在所有需要分頁的模板中調(diào)用,實(shí)現(xiàn)代碼的重用性,下面用實(shí)例演示完整的分頁模板。

    @{
    ???//實(shí)例化一個(gè)分頁信息描述類
    ???PageInfo?pageInfo?=?new?PageInfo()
    ????????{
    ????????????PageSize?=?10,
    ????????????CurrentPage?=?ViewBag.CurrentPage?//系統(tǒng)預(yù)設(shè)
    ????};
    ????int?columnId?=?Html.CurrentColumnId();//獲取當(dāng)前欄目id
    ????var?dataList?=?Html.InfoDataList(new?{?ColumnId?=?columnId,?OrderBy?=?"thedate?desc"?},?null,?null,?pageInfo);
    }
    <div?class="news-list">
    ????@foreach?(var?item?in?dataList)
    ????{
    ????????string?url?=?Html.InfoDataUrl((int)item.ColumnId,?(int)item.Id);?//獲取信息內(nèi)容頁url,固定語法。
    ????????<div>
    ????????????<div?class="title"><a?href="@url"?target="_blank">@item.Title</a></div>
    ????????????<div?class="date">@item.Thedate</div>
    ????????</div>
    ????}
    </div>
    @Html.Partial("PagebreakPartial",?pageInfo)

    模板制作人員可以在上面代碼基礎(chǔ)上完善,其中的@Html.Partial("PagebreakPartial", pageInfo)就是調(diào)用分頁局部視圖,第一個(gè)參數(shù)為文件名,第二個(gè)參數(shù)為PageInfo描述類,大家記得這種固定語法就可以了。


    本頁內(nèi)容由塔燈網(wǎng)絡(luò)科技有限公司通過網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶參考了本站不擁有所有權(quán),如您認(rèn)為本網(wǎng)頁中由涉嫌抄襲的內(nèi)容,請(qǐng)及時(shí)與我們聯(lián)系,并提供相關(guān)證據(jù),工作人員會(huì)在5工作日內(nèi)聯(lián)系您,一經(jīng)查實(shí),本站立刻刪除侵權(quán)內(nèi)容。本文鏈接:http://www.juherenli.com/19139.html
    相關(guān)cms文章
     八年  行業(yè)經(jīng)驗(yàn)

    多一份參考,總有益處

    聯(lián)系深圳網(wǎng)站公司塔燈網(wǎng)絡(luò),免費(fèi)獲得網(wǎng)站建設(shè)方案及報(bào)價(jià)

    咨詢相關(guān)問題或預(yù)約面談,可以通過以下方式與我們聯(lián)系

    業(yè)務(wù)熱線:余經(jīng)理:13699882642

    Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.    

    久久久久人妻一区精品色| 国产精品伦理久久久久久| 久久夜色精品国产噜噜噜亚洲AV| 青青草99热这里都是精品| 青娱乐2017年精品视频在线| 青草国产精品久久久久久| 伊人久久国产精品| 一本色道久久88综合亚洲精品高清| 久久频这里精品99香蕉久| 久久亚洲美女精品国产精品| 亚洲乱码精品久久久久..| 日韩精品无码永久免费网站| 成人无码精品一区二区三区| 精品国偷自产在线| 久久国产精品萌白酱免费| 中文字幕一区精品| 亚洲精品国产精品乱码不卞| 青青国产精品视频| 亚洲国产精品18久久久久久| 亚洲乱码日产精品BD在线观看| 无码国产69精品久久久久网站| 亚洲综合精品香蕉久久网| 国产精品一区二区三区99| 四虎国产精品永免费| 国产在线精品美女观看| 精品伊人久久久久网站| 国产精品白丝AV在线观看播放| 亚洲综合久久精品无码色欲| 精品国产福利在线观看| 揄拍自拍日韩精品| 久久国产精品77777| 99精品国产三级在线观看| 久久亚洲精品中文字幕无码| 亚洲国产精品无码AAA片| 国产精品99精品久久免费| 亚洲日韩一页精品发布| 亚洲国产另类久久久精品黑人 | 国产精品香港三级国产AV| 香蕉在线精品一区二区| 中文字幕精品在线| 国产亚洲精品va在线|