I have a Carro
object and I have an integer and nullable property called AnoInspecao
. When creating, I can create a car object with the null inspection year (without typing anything) and persist in the database normally.
var carro = new Carro()
{
carro.AnoInspecao = null;
carro.Nome = "meuCarro"
}
At the time of editing ( View ), I use the following code:
@Html.TexboxFor(model => model.AnoInspecao)
But it does not work, because Textbox
does not accept null, thus generating Exception
.
How can I handle this?