Ejemplo n.º 1
0
        /// <summary>
        /// 选择查询
        /// </summary>
        /// <param name="pagingModel"></param>
        /// <returns></returns>
        public virtual ActionResult Query([ModelBinder(typeof(PagingModelBinder))] PagingModel pagingModel)
        {
            pagingModel.PageSize = 10;
            var    expression = LambdaHelper.BuildQueryCondition <T>(pagingModel);
            object lstData;

            if (pagingModel.QueryFields == "Code,Name") //TODO:不同的查询列表不同字段列表
            {
                IEnumerable <T> list = model.GetList(expression);

                //TODO: 直接使用IPagination<T>无法转换
                var data = Mapper.Map <IEnumerable <T>, IEnumerable <QueryViewModel> >(list)
                           .OrderBy(pagingModel.SortOptions.Column, pagingModel.SortOptions.Direction)
                           .AsPagination(pagingModel.PageIndex, pagingModel.PageSize, pagingModel.SortOptions);

                lstData = data;
            }
            else
            {
                IPagination <T> list = model.GetPagedList(pagingModel, expression);
                lstData = list;
            }

            ViewBag.Sort  = pagingModel.SortOptions;
            ViewBag.Query = pagingModel.Query;

            if (Request.HttpMethod == "GET")
            {
                return(PartialView("_Query", lstData));
            }

            //默认是PUT
            return(PartialView("Query", lstData));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 首次加载、列表操作、翻页、排序、刷新、搜索查询
        /// </summary>
        /// <param name="pagingModel"></param>
        /// <returns></returns>
        public virtual ActionResult Index([ModelBinder(typeof(PagingModelBinder))] PagingModel pagingModel)
        {
            var             expr = LambdaHelper.BuildQueryCondition <T>(pagingModel);
            IPagination <T> list = model.GetPagedList(pagingModel, expr);

            ViewBag.Sort = pagingModel.SortOptions;

            if (Request.IsAjaxRequest())
            {
                if (Request.HttpMethod == "GET")
                {
                    return(PartialView("_Index", list));
                }
                else
                {
                    return(Json(new SuccessActionResult("Ok", list)));
                }
            }

            return(View("Index", list));
        }