码迷,mamicode.com
首页 > Web开发 > 详细

mvcpager之学习

时间:2017-08-07 13:44:20      阅读:219      评论:0      收藏:0      [点我收藏+]

标签: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之学习

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!