public ActionResult Create([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人) { var data = repo.Email重覆判斷(客戶聯絡人.Email, 客戶聯絡人.Id); //if (db.客戶聯絡人.Any(x=>x.Email == 客戶聯絡人.Email && x.Id != 客戶聯絡人.Id)) if (data.Any()) { ModelState.AddModelError("Email", "Email輸入不可重覆!!"); } else { if (ModelState.IsValid) { //db.客戶聯絡人.Add(客戶聯絡人); //db.SaveChanges(); repo.Add(客戶聯絡人); repo.UnitOfWork.Commit(); return(RedirectToAction("Index")); } } //ViewBag.客戶Id = new SelectList(db.客戶資料, "Id", "客戶名稱", 客戶聯絡人.客戶Id); ViewBag.客戶Id = new SelectList(repo_客.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id); return(View(客戶聯絡人)); }