public IActionResult AddAdminMenu(AdminMenu model) { if (!ModelState.IsValid) { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); tip.Message = messages; return(Json(tip)); } //判断 if (AdminMenu.FindCount(AdminMenu._.MenuKey == model.MenuKey, null, null, 0, 0) > 0) { tip.Message = "菜单KEY已经存在,请填写其他的!"; } IList <TargetEvent> listevent = TargetEvent.FindAll(null, TargetEvent._.Rank.Asc(), null, 0, 0); string[] eventkeys = Request.Form["eventkey"]; List <AdminMenuEvent> listme = new List <AdminMenuEvent>(); if (eventkeys != null && eventkeys.Length > 0) { foreach (string s in eventkeys) { if (Utils.IsInt(s)) { TargetEvent te = listevent.FirstOrDefault(t => t.Id == int.Parse(s)); if (te != null) { AdminMenuEvent tmp = new AdminMenuEvent(); tmp.EventId = te.Id; tmp.EventKey = te.EventKey; tmp.EventName = te.EventName; tmp.MenuKey = model.MenuKey; listme.Add(tmp); } } } } model.Insert(); if (listme != null && listme.Count > 0) { listme.ForEach(s => { s.MenuId = model.Id; }); listme.Insert(); } tip.Status = JsonTip.SUCCESS; tip.Message = "添加后台菜单成功"; tip.ReturnUrl = "close"; return(Json(tip)); }