Format date within View in ASP.NET Core MVC
Simple and practical, use asp-format
, example:
<input asp-for="MyDate" asp-format="{0:dd/MM/yyyy}" class="form-control" />
Or:
@Html.TextBoxFor(model => model.MyDate, "{0:dd/MM/yyyy}", new { @class = "form-control" })
Thank you @Enrico for your comment i add it in the answer :
Try it with this in your model:
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
And In your controller change DateTime to Date :
myList.loanContract = new LoanContract { LoanDateStart = Date.Today };
Hope this help you.