public ActionResult Edit(WxArtcle wc, Article at) { if (string.IsNullOrWhiteSpace(at.Title)) { ModelState.AddModelError("", "标题不能为空"); return(View(wc)); } wc.Description = ArticleHelper.ArticleToString(at); Boolean isHas = db.WxArtcle.Where(d => d.Name.ToUpper() == wc.Name.ToUpper() && d.Id != wc.Id).Any(); if (wc.Id == 0) { /* * 验证Name重复了 */ if (isHas) { ModelState.AddModelError("", "名称不能重复"); return(View(wc)); } db.WxArtcle.Add(wc); } else { if (isHas) { ModelState.AddModelError("", "名称不能重复"); return(View(wc)); } db.Entry(wc).State = EntityState.Modified; } try { db.SaveChanges(); } catch { return(View(wc)); } //WPconfig.UpdatewxDictKeyValue<WxArtcle>(); return(RedirectToAction("Index")); }