日期:2014-05-17 浏览次数:20394 次
[HttpPost] public ActionResult UserJson(int? id,int? page, int? rows, string model) { int Page = page ?? 1; int Rows = rows ?? 10; QueryModel QModel = null; Dictionary<string, object> JsonObj = new Dictionary<string, object>(); if (!string.IsNullOrWhiteSpace(model)) { QModel = IntelligentQuery.AjaxQueryConverter.ToQueryModel(model); } if (id.HasValue) { JsonObj.Add("total", UserRepository.Get(QModel).Where(w => w.Position.OrganID == id).Count()); } else { JsonObj.Add("total", UserRepository.Get(QModel).Count()); } if (id.HasValue) { JsonObj.Add("rows", UserRepository.Get(QModel, orderBy: o => o.OrderBy(u => u.Position.PositionLevel)).Where(w => w.Position.OrganID == id) .Skip((Page - 1) * Rows) .Take(Rows) .Select(s => new { s.UserNo,s.Password, s.RealName, s.Sex, s.Birthday, s.IDCardNumber, s.Height, s.IsDisabled, s.Country, s.DomicilePlace, s.IsMarried, s.PoliticsStatus, s.Education, s.GraduateSchool, s.Degree, s.DegreeBySchool, s.ResidentialAddress, s.Post, s.TelPhoneNumber, s.Email, s.QQ, s.MSN, s.JoinDate, s.PositionID, s.Position.PositionName,s.Position.Organization.OrganID, s.Position.Organization.OrganName, s.State, s.PayType, s.CheckType,s.IsSuper, s.Remark, s.IsEnable })); } else { JsonObj.Add("rows", UserRepository.Get(QModel, orderBy: o => o.OrderBy(u => u.Position.PositionLevel)) .Skip((Page - 1) * Rows) .Take(Rows) .Select(s => new { s.UserNo, s.Password, s.RealName, s.Sex, s.Birthday, s.IDCardNumber, s.Height, s.IsDisabled, s.Country, s.DomicilePlace, s.IsMarried, s.PoliticsStatus, s.Education, s.GraduateSchool, s.Degree, s.DegreeBySchool, s.ResidentialAddress, s.Post, s.TelPhoneNumber, s.Email, s.QQ, s.MSN, s.JoinDate, s.PositionID, s.Position.PositionName, s.Position.Organization.OrganID, s.Position.Organization.OrganName, s.State, s.PayType, s.CheckType, s.IsSuper, s.Remark, s.IsEnable })); } Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter();//这里使用自定义日期格式,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd";//设置时间格式 string json = Newtonsoft.Json.JsonConvert.SerializeObject(JsonObj, Newtonsoft.Json.Formatting.Indented, timeConverter);//转换序列化的对象 return Content(json, "application/json"); }