MVC中实现分页

ContractedBlock.gif ExpandedBlockStart.gif Code
 //分页时参数
    public interface IPaginationParameters
    {
        
int? PageNumber { get; }
        
int? PageSize { get; }
    }

    
//排序方向枚举
    public enum SortDirection
    {
        Ascending, 
//升序
        Descending //降序
    }

    
public class SortCondition<T> //排序条件
    {
        
public SortCondition() { }

        
public SortCondition(T sortType, SortDirection sortDirection)
        {
            SortType 
= sortType;
            SortDirection 
= sortDirection;
        }
        
public T SortType { getset; } //排序类型{枚举:实体类为枚举名,属性为枚举值}
        public SortDirection SortDirection { getset; } //升、降序
    }

    
public class SortForm<SortType> //排序条件集合
    {
        
public SortForm() { }

        
public IList<SortCondition<SortType>> SortConditions { getset; }//排序条件集合
    }

    
public class PaginationSortForm<SortType> : SortForm<SortType>, IPaginationParameters
    {
        
public PaginationSortForm()
        {
            PageNumber 
= 1;
            PageSize 
= 15;
        }

        
public PaginationSortForm(int pageNumber, int pageSize)
        {
            PageNumber 
= pageNumber;
            PageSize 
= pageSize;
        }

        
public void Clear()
        {
            PageNumber 
= null;
            PageSize 
= null;
        }

        
public int? PageNumber { getprivate set; }//当前页码
        public int? PageSize { getprivate set; }//每页显示记录数
    }

    
/***********************************************************************/
    
//排序类型{枚举:实体类为枚举名,属性为枚举值}

    
public interface ISortParameters<SortType> //排序条件集合
    {
        IList
<SortCondition<SortType>> SortConditions { get; } //排序条件集合
    }

    
public interface IPaginationSortParameters<SortType> : ISortParameters<SortType>
    {
        
int? StartIndex { get; }
        
int? MaxCount { get; }
    }

    
public class SortParameters<SortType> : ISortParameters<SortType>
    {
        
public IList<SortCondition<SortType>> SortConditions { getset; }
        
//ctor
        public SortParameters(SortType sortType, SortDirection sort)
        {
            
if (SortConditions == null || SortConditions.Count == 0)
            {
                SortConditions 
= new List<SortCondition<SortType>>();
                SortConditions.Add(
new SortCondition<SortType>(sortType, sort));
            }
        }
        
//ctor
        public SortParameters(SortForm<SortType> sortForm, SortType sortType, SortDirection sort)
        {
            
if (sortForm == null)
            {
                sortForm 
= new SortForm<SortType>();
            }
            
this.SortConditions = sortForm.SortConditions;
            
if (SortConditions == null || SortConditions.Count == 0)
            {
                SortConditions 
= new List<SortCondition<SortType>>();
                SortConditions.Add(
new SortCondition<SortType>(sortType, sort));
            }
        }
    }

    
public class PaginationSortParameters<SortType> : SortParameters<SortType>,
                                                      IPaginationSortParameters
<SortType>
    {
        
public PaginationSortParameters(PaginationSortForm<SortType> form,
                                    SortType sortType, SortDirection sort)
            : 
base(form, sortType, sort)
        {
            MaxCount 
= form.PageSize;
            StartIndex 
= (form.PageNumber.Value - 1* form.PageSize.Value;//起始索引
        }

        
public int? StartIndex { getprivate set; }
        
public int? MaxCount { getprivate set; }
    }

转载于:https://www.cnblogs.com/ycdx2001/archive/2009/06/25/1510793.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值