public JsonResult Get(int pageIndex, int pageSize, string pageOrder, int id) { var list = CartItems.GetOrderItems(id); foreach (var item in list) { string[] name = new string[item.Gifts.Count]; if (item.Gifts.Count > 0) { int i = 0; foreach (var gift in item.Gifts) { name[i] = gift.GiftTitle; i++; } item.ProductTitle += "<br/>" + "<i class='icon-gift'></i>" + String.Join(",", name); } } int total = CartItems.CountOrderItems(id); int totalPage = (int)Math.Ceiling((decimal)total / pageSize); if (pageSize > total) { pageSize = total; } if (list.Count < pageSize) { pageSize = list.Count; } JsonResult result = new JsonResult() { Data = new { TotalPages = totalPage, PageIndex = pageIndex, PageSize = pageSize, Rows = list }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(result); }