Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5.2 How to set default value for datetime-local?

 @Html.EditorFor(m => m.DateOfAcception, new
                {
                    htmlAttributes = new { type = "datetime-local", required = "required" },
                    @class = "form-control datepicker",
                    @value = DateTime.Now.ToString()
                })

I got something like that but the Value is not working also my model is

public DateTime DateOfAcception { get; set; } = DateTime.Now;

But i cant get it to start with default value.

This is how it looks in html

enter image description here

The part Novo is just @Html.EditorFor(m => m.DateOfAcception) if the left side part can start with that value like that somehow

like image 406
Darkogele Avatar asked Sep 13 '25 11:09

Darkogele


1 Answers

You should use TextBoxFor and put international time and then Razor will convert it to local date time. I hope this will answer your question.

  @Html.TextBoxFor(x => x.DateOfAcception, "{0:yyyy-MM-ddTHH:mm:ss}", new
                       {
                           @class = "form-control",
                           required = "required",
                           @type = "datetime-local"
                       })
like image 70
Bozhinovski Avatar answered Sep 15 '25 01:09

Bozhinovski