public ActionResult Create(Roles roles, FormCollection form) { if (ModelState.IsValid) { //var idList = form["idList"].Split(','); //roles.RolesClass = new List<RolesClass>(); db.Roles.Add(roles); //roles.RolesClass = new List<RolesClass> { new RolesClass { ClassID = 1 } }; roles.RolesClass.Add(new RolesClass { ClassID = 1 }); db.SaveChanges(); } return(RedirectToAction("Create")); }
public ActionResult Create(sysClass model) { if (model.ClassID == 0) { model.ParentID = 0; model.ParentPath = "0"; model.Depth = 0; } else { int classid = model.ClassID; var parent = db.sysClass.First(m => m.ClassID == classid); model.ParentID = classid; model.ParentPath = $"{parent.ParentPath},{parent.ClassID}"; model.Depth = parent.Depth + 1; } db.sysClass.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); }