I am new to MVC, I want to know how I can validate that at the moment of deleting a parent record I am shown a message that tells the user that it can not be deleted because of the relationship with the child records.
I have a validation in the create POST of my controller which is the following:
public ActionResult Create([Bind(Include = "AreaId,NameArea")] Area area)
{
if (db.Area.Any(a => a.NameArea == area.NameArea))
{
ModelState.AddModelError("NameArea", "Ya existe una Área con este nombre.");
}
if (ModelState.IsValid)
{
db.Area.Add(area);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(area);
}
I would like to validate the deletion similar to the previous one, or if there were any other way I would appreciate it.