private bool CheckValidateContact(WebAPP.Models.Contact obj) { ModelState.Clear(); if (string.IsNullOrEmpty(obj.Name)) ModelState.AddModelError("Name", "Name is required !"); if (string.IsNullOrEmpty(obj.Email)) ModelState.AddModelError("Email", "Email is required !"); if (string.IsNullOrEmpty(obj.Title)) ModelState.AddModelError("Title", "Title is required !"); if (string.IsNullOrEmpty(obj.Address)) ModelState.AddModelError("Address", "Address is required !"); if (string.IsNullOrEmpty(obj.Phone)) ModelState.AddModelError("Phone", "Phone is required !"); if (string.IsNullOrEmpty(obj.Content)) ModelState.AddModelError("Content", "Content is required !"); return ModelState.IsValid; }
public ActionResult SaveContact(WebAPP.Models.Contact obj) { if (CheckValidateContact(obj)) { db.Contacts.Add(obj); db.SaveChanges(); return RedirectToAction("Contact"); } else { return View("Contact", obj); } }