0
Guys I’m having a problem when clicking save with some data filled ends up giving error how could solve.
By clicking save from this error This is the controller to create
public ActionResult Create(Empresa empresa) { if (ModelState.IsValid) {
db.Empresas.Add(empresa); db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CidadeId = new SelectList(CombosHelper.PegarCidade(empresa.DepartamentoId), "CidadeId", "Nome", empresa.CidadeId);
ViewBag.DepartamentoId = new SelectList(CombosHelper.PegarDepartamento(), "DepartamentoId", "Nome", empresa.DepartamentoId);
return View(empresa);
}
This is the function that takes the city.
public Static List Pegarcidade(int departamentoid) { var cidade = db.Cidades.Where(Cid=>Cid.Departamentoid == departamentoid). Tolist(); Add city.Add(new city { Departamentoid = 0, Name = "[ Select a City ]" });
return cidade = cidade.OrderBy(dep => dep.Nome).ToList();
}
If you choose the department and the city, it saves normal, just when you try to save without choosing, you need to put some message that you can’t, but I’m not getting it.