mvcpager之學習

來源:互聯網
上載者:User

標籤:nat   sed   cti   targe   next   style   cPage   分享   using   

一、項目中必須引用MVCpager.dll,現在是3.0版本。

二、添加頁面view.Model

namespace Model.ViewModel{    public class VolumeTree    {        public int VolumeID { get; set; }        public string VolumeName{ get; set; }        public List<Subsection> SubsectionS { get; set; }    }    public class Subsection    {        public int SubsectionID { get; set; }        public string SubsectionName { get; set; }               public string PoetryName { get; set; }            }    public class Poet {        public int PoetID { get; set; }        public string powtName { get; set; }    }    public class Poetry    {        public int PoetryID { get; set; }        public string PoetryName { get; set; }        public Poet poet { get; set; }            }}
View Model

 三、控制器代碼,也是預設頁面index

 public ActionResult index(int? id = 1)        {            // List<Model.ViewModel.VolumeTree> VolunePage = new List<Model.ViewModel.VolumeTree>();            // int totalCount = 0; /*OperateContext.Current.BLLSession.IVolumeBLL.GetListBy_NoTrack(s => s.VolumeID > 0).ToList().Count();*/            int pageIndex = id ?? 1;            // var VolunePage = OperateContext.Current.BLLSession.IVolumeBLL.getPageDate(pageIndex, 2,s=>s.VolumeID>0,s=>s.VolumeID, out totalCount,true);            var VolunePage = OperateContext.Current.BLLSession.IVolumeBLL.GetListBy_NoTrack(s => s.VolumeID > 0).Select(s => new Model.ViewModel.VolumeTree            {                VolumeID = s.VolumeID,                VolumeName = s.VolumeName,                SubsectionS = s.Subsection.Select(u => new Model.ViewModel.Subsection                {                    SubsectionID = u.SubsectionID,                    SubsectionName = u.SubsectionName,                    PoetryName = u.Poetries.Select(p => p.PoetryName).FirstOrDefault()                }).ToList()            }).ToList();            PagedList<Model.ViewModel.VolumeTree> mPage = new PagedList<Model.ViewModel.VolumeTree>(VolunePage, pageIndex, 5);            //mPage.TotalItemCount = totalCount;            //mPage.CurrentPageIndex = (int)(id ?? 1);                                 if (Request.IsAjaxRequest())            {                return PartialView("VolumeTreeMvcPager", mPage);            }            return View(mPage);
控制器代碼

四、index頁面cshtml,這是第一視圖,擷取model,同時傳給VolumeMvcpagerTree.cshtml

@model PagedList<Model.ViewModel.VolumeTree>@using Webdiyer.WebControls.Mvc;@{    ViewBag.Title = "index";    Layout = "~/Views/Shared/_Layout.cshtml";}<div>    <h2>管理</h2>    <div id="MVCpager">        @Html.Partial("VolumeMvcpagerTree", Model)    </div></div>
index頁面

 五、局部視圖,將首頁index的Model解析,綁定資料,使用者呈現,主要是要把Mvcpager的分頁html.help搞定

@model PagedList<Model.ViewModel.VolumeTree>@using Webdiyer.WebControls.Mvc;<ul>    @if (Model != null)    {        foreach (var item in Model)        {            <li>                @item.VolumeName<span>‘<a href="javascript:;">增加分卷</a></span>                <ul>                    @if (item != null)                    {                        foreach (var Sub in item.SubsectionS)                        {                            <li>@Sub.SubsectionName</li> }                    }                </ul>            </li>        }    }</ul>@if (Model != null){    <div class="text-center">        @Ajax.Pager(Model, new PagerOptions   {       PageIndexParameterName = "id",       FirstPageText = "首頁",       PrevPageText = "上一頁",       NextPageText = "下一頁",       LastPageText = "末頁",       NumericPagerItemCount = 5,       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>"   }).AjaxOptions(a => a.SetUpdateTargetId("MVCpager"))    </div>}
View Code

 

mvcpager之學習

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.