0

I am working on an ASP.NET MVC application. My model has a DateTime field i.e.

[DisplayFormat(DataFormatString = "{0:h:mm tt}")] [DataType(DataType.DateTime)] public DateTime? CompletedDate { get; set; } 

I have to show this in a DateTime control on front end (cshtml). My code for this in cshtml is:

@Html.TextBoxFor(m => m.model.CompletedDate, new { type = "datetime-local" }) 

Value of model.CompletedDate is 2020-06-15 11:00:00.000 but i don't get this value binded with my control. I get this:

enter image description here

I have to use DateTime control and can not use simple textbox. Can anyone help me. I am stuck here and didn't find anything on the google yet.

1 Answer 1

1

The format string needs to be "{0:s}", i tried this and it's work fine for me :

@Html.TextBoxFor(m => m.model.CompletedDate,"{0:s}", new { type = "datetime-local" }) 

I hope you find this helpful.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.