Model
public class Transacao
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
[Required]
public DateTime Data { get; set; }
[Required]
public decimal Valor { get; set; }
}
Controller
public ActionResult ManterTransacao(int idTransacao = 0)
{
(...)
Transacao transacao = null;
if (idTransacao > 0)
{
transacao = new DaoTransacao().DadosTransacao(idTransacao);
}
}
View
@model Web.Models.Transacao
(...)
if (Model != null)
{
<input type="hidden" name="idTransacao" value="@Model.ID" />
}
My controller
is meant to include E update data across the same view. If it is a data refresh, the input="hidden"
name idTransacao
is included on the page. This insertion occurs when Model
is not null, as shown in the controller (the object reference is only created if the value of the idTransacao
parameter is given and is greater than 0).
However, this validation fails:
Object reference not set to an instance of an object.
Since the object passed as a template to the view is null, where is the error?