1
I’m trying to register a project in a certain area, but every time I try to register it returns an exception.
Exception:
An Exception of type 'System.Data.Entity.Infrastructure.Dbupdateexception' occurred in Entityframework.dll but was not handled in user code
Conversion failed when Converting the varchar value 'COL' to data type int.
My controller:
// GET: Projeto/Create
public ActionResult Create()
{
ViewBag.proArea = new SelectList(db.tblArea, "areIdArea", "areArea");
return View();
}
// POST: Projeto/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "proIdProjeto,proNome,proArea")] tblProjeto tblProjeto)
{
if (ModelState.IsValid)
{
db.tblProjeto.Add(tblProjeto);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.proArea = new SelectList(db.tblArea, "areIdArea", "areArea", tblProjeto.proArea);
return View(tblProjeto);
}
My Class:
public partial class tblProjeto
{
[Key]
public int proIdProjeto { get; set; }
[Required(ErrorMessage = "Inform o nome deo projeto")]
[Display(Name = "Nome")]
public string proNome { get; set; }
[Required(ErrorMessage = "informe a area")]
[Display(Name = "Area")]
public Nullable<int> proArea { get; set; }
public virtual tblArea tblArea { get; set; }
}
I don’t really know how to fix it, I researched it here, but I didn’t find any examples that came close to my need. I’d like to know why you keep making this exception and how can I fix it? I ask for your help and I’m sorry if anything is wrong.