Not null parameter in Int fields

Asked

Viewed 264 times

0

I am creating an application in Asp.NET MVC (I am using the Scafffolded feature), however, all the whole fields are being required to be filled in, as I remove this parameter?

Note: I have tried to uncheck the "Allow null value" option in the database, but without success.

I’m guessing this validation is taking place at .cshtml, but I couldn’t locate.

Model.

public class prospectModel 
{ 
    public int id { get; set; } 
    public string contato { get; set; } 
    public string nomeRazaoSocial { get; set; } 
    public int documento { get; set; } 
    public int telefone { get; set; } 
    public int celular { get; set; } 
    public string email { get; set; } 
    public string anotacoes { get; set; } 
}

cshtml

<div class="form-group"> @Html.LabelFor(model => model.celular, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> @Html.EditorFor(model => model.celular, new { htmlAttributes = new { @class = "form-control" } })@Html.ValidationMessageFor(model => model.celular, "", new { @ class = "text-danger" })
    </div> 
</div>
  • How is your model? The properties are as Required?

  • It depends, the html it fills as required only some data types ... as for example type: number ... your . cshtml is as ?

  • It’s not like Required :(

  • Edit your answer, do not get code in the comments that the view looks bad.

1 answer

0


Since integer is a primitive type it does not allow null values, in your case it must accept, ie you must mark this property as nullable in your model view:

public int? Idade {get; set; }
  • 1

    I put the "?", updated the database, and compiled, and it worked! Thanks =D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.