Mark Tabor

Mark Tabor

  • 589
  • 2k
  • 460.1k

how to check already existing record in mvc

Jan 14 2018 5:28 AM
I am new to mvc and i am creating application with built in read/write controller and views using entity framework , below is my create customer controller now i want to check the unique mobile number i mean mobile number for each customer should be unique , how to check that below is my controller code.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Cutomer_ID,Customer_Name,Phone,Location,Email,gender")] Customer customer, string BtnPrevious, string BtnNext)
{
// bool isexists = db.customers.Any(x => x.ContactId == _customer.ContactId)
if (ModelState.IsValid)
{
//bool contactExists = db.Customers.Any(contact => contact.Customer_Name.Equals());
db.Customers.Add(customer);
db.SaveChanges();
// return View("~/Views/Orders/Details.cshtml");
// return RedirectToAction("~/Views/Shirts/Index.cshtml");
}
return View(customer);
}
 

Answers (1)