0
I have a form and whenever someone register, I need to save the time of registration in my table Historico2 inside the property DateTime? Quando
.
public partial class Historico2
{
public int ID { get; set; }
[Required]
[StringLength(50)]
public string Quem { get; set; }
public DateTime? Quando { get; set; }
public decimal Peso { get; set; }
public decimal Valor { get; set; }
public decimal? TOTAL { get; set; }
}
How can I pass the amount DateTime.Now()
whenever someone registers for the property DateTime? Quando
?
Actionresult Create() from my controller:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ID,Quem,Quando,Peso,Valor,TOTAL")] Historico2 historico2)
{
if (ModelState.IsValid)
{
db.Historico2.Add(historico2);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(historico2);
}
Use
Triggers
in your application and stop worrying about the dates in your business logic: https://www.nuget.org/packages/EntityFramework.Triggers https://github.com/NickStrupat/EntityFramework.Triggers– Armindo Gomes
Thanks for the tip Armindo!
– Vinix Gonzalez