3

Here's my model's property:

[Required(ErrorMessage = "Debe escribir su fecha de nacimiento")]
[Display(Name = "Fecha de Nacimiento")]
[DataType(DataType.Date)]
public DateTime DateOfBirth { get; set; }

In my AccountController, I create a new object of this model and pass it to the View:

<div class="editor-label">
    @Html.LabelFor(model => model.DateOfBirth)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.DateOfBirth)
    @Html.ValidationMessageFor(model => model.DateOfBirth)
</div>

Remember, at this point this is a Create form. The model's properties have no values.

However, this is rendered in my HTML.

enter image description here

Is there some way to tell the view engine to not render anything in this field?

1 Answer 1

4

If you change your definition to a Nullable, then it'll start off as null and no value will be displayed if one isn't set (which by default it isn't).

public DateTime? DateOfBirth { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.