2
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" />
}
Man controller
serves to include And update data through the same view. If it is a data update, the input="hidden"
by name idTransacao
is included on the page. This insertion occurs when Model
is not null, as shown in the controller (the object reference is created only if the parameter value idTransacao
is supplied 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 view model is null, where is the error?
Great Gypsy! As always, irreproachable in the placements.
– Tiago César Oliveira