I have a table named Pecas where only has name and value, but when I click on create new piece is not saving in the database, the msg that was added but not inserting, the debug shows the name but the value always it's coming 0 no matter what the value I put.
Table
public class Pecas
{
public int Id { get; set; }
public string Nome { get; set; }
public decimal ValorUnitatio { get; set; }
}
TableVM
public PecasVM()
{
}
public PecasVM(Pecas row)
{
Id = row.Id;
Nome = row.Nome;
ValorUnitatio = row.ValorUnitatio;
}
public int Id { get; set; }
public string Nome { get; set; }
public decimal ValorUnitatio { get; set; }
My controller
public ActionResult Criar()
{
return View();
}
[HttpPost]
public ActionResult Criar(PecasVM model)
{
if (ModelState.IsValid)
{
using (Db db = new Db())
{
Pecas pec = new Pecas();
pec.Nome = model.Nome;
pec.ValorUnitatio = model.ValorUnitatio;
db.Pecas.Add(pec);
db.SaveChanges();
}
}
TempData["MSG"] = "Peça adicionada com sucesso.";
return RedirectToAction("Index");
}