public ActionResult Create([Bind(Include = "RoleName")] Rol objectViewModel) { List <KeyValuePair <int, string> > listModulosChk = new List <KeyValuePair <int, string> >(); try { if (ModelState.IsValid) { ModuloPermisoRepository moduloPermisoRepository = new ModuloPermisoRepository(); objectRepository.Add(objectViewModel, this.User.UserID); foreach (var item in Request.Form) { if (item.ToString().StartsWith("chk")) { string[] arrItem = item.ToString().Split('_'); listModulosChk.Add(new KeyValuePair <int, string>(int.Parse(arrItem[2]), arrItem[1])); } } foreach (var item in listModulosChk) { ModuloPermiso mPermiso = new ModuloPermiso(); mPermiso.Accion = item.Value; mPermiso.Modulo_Id = item.Key; mPermiso.Rol_Id = objectViewModel.Id; moduloPermisoRepository.Add(mPermiso, this.User.UserID); } return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Error al guardar datos del Rol, comuniquese con su admnistrador :" + ex.Message); } PopulateTreeModulosEmpty(); return(View(objectViewModel)); }