How do I assign a default date value to a TextBoxFor?

2

I have the following TextBoxFor

@Html.TextBoxFor(model => model.data, "{0:dd/MM/yyyy}", new { @class = "form-control", @alt = "date", @placeholder = DateTime.Now.Date.ToString("dd/MM/yyyy"), @maxlength = "10", @data_val="false"})

As you can see, there is a placeholder that defines what will be displayed on it when the screen is opened. My question is: How do I put today's date in the actual content of TextBoxFor? For example, when I open the screen without filling in the textBox it accuses it of being empty, that is, it is being displayed that today's date is set in the field but only visually.

Thank you.

    
asked by anonymous 24.05.2017 / 21:42

1 answer

1

As the Pablo Carvalho commented, you should add the value property to your object

@Html.TextBoxFor(model => model.data, "{0:dd/MM/yyyy}", new { @class = "form-control", 
@alt = "date", @placeholder = DateTime.Now.Date.ToString("dd/MM/yyyy"), 
@maxlength = "10", @data_val="false", @value = DateTime.Now.Date.ToString("dd/MM/yyyy")})
    
21.09.2017 / 16:38