public ActionResult UpdateRole(Roles data, string updateType) { if (string.IsNullOrEmpty(updateType)) { updateType = "1"; } UserDbContext uc = new UserDbContext("ConnStr1"); try { switch (updateType) { case "1": if (data != null) { data = uc.AddRole(data); uc.SaveChanges(); } else { data = new Roles(); } break; case "2": if (data == null) { throw new Exception("数据为空,无法更新。"); } uc.ModifyRole(data); uc.SaveChanges(); break; case "3": if (data == null) { throw new Exception("数据为空,无法删除。"); } uc.DeleteRole(data); uc.SaveChanges(); break; default: throw new Exception("更新类型出错。"); } //return View(data); //var script = String.Format("<script>alert('更新成功!');location.href='{0}';</script>", Url.Action("UpdateRole")); string script = MvcUT.ShowAlertAndHref(this, "更新成功", "UpdateRole", new { updateType = 2, id = data.RoleID }); return(Content(script, "text/html")); } catch (Exception ex) { if (ex.Message != null) { } this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message; return(View(data)); } }