mvcpager之学习

2021-06-09 22:03

阅读:846

标签: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 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 VolunePage = new List();
            // 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 mPage = new PagedList(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 PagedListModel.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
@using Webdiyer.WebControls.Mvc;

    @if (Model != null) { foreach (var item in Model) {
  • @item.VolumeName增加分卷
      @if (item != null) { foreach (var Sub in item.SubsectionS) {
    • @Sub.SubsectionName
    • } }
  • } }
@if (Model != null) {
class="text-center"> @Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id", FirstPageText = "首页", PrevPageText = "上一页", NextPageText = "下一页", LastPageText = "末页", NumericPagerItemCount = 5, ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "
  • {0}
  • ", DisabledPagerItemTemplate = "
  • {0}
  • ", PagerItemTemplate = "
  • {0}
  • " }).AjaxOptions(a => a.SetUpdateTargetId("MVCpager"))
    }
    View Code

     

    mvcpager之学习

    标签:nat   sed   cti   targe   next   style   cPage   分享   using   

    原文地址:http://www.cnblogs.com/cqstars/p/7298337.html


    评论


    亲,登录后才可以留言!