mvcpager之学习

技术分享
namespace Model.ViewModel
{
    public class VolumeTree
    {
        public int VolumeID { get; set; }
        public string VolumeName{ get; set; }
        public ListSubsection 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)
        {
            // ListModel.ViewModel.VolumeTree VolunePage = new ListModel.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.VolumeID0,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();
            PagedListModel.ViewModel.VolumeTree mPage = new PagedListModel.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 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 PagedListModel.ViewModel.VolumeTree
@using Webdiyer.WebControls.Mvc;

ul

    @if (Model != null)
    {
        foreach (var item in Model)
        {
            li
                @item.VolumeNamespana 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之学习

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


最新回复(0)
/jishuo9qrSHxBSUDRBilNIKN8ZgjAUVIysLsIQHBwNA_3D_3D4719020
8 简首页