HI WELCOME TO SIRIS

Format date within View in ASP.NET Core MVC

Leave a Comment
regarding with converting the datetime to date using a model.
Model from Class Library
public partial class LoanContract
{
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")
public DateTime LoanDateStart { get; set; }
}
Model from Project
public class ModelLoan
{
    public LoanContract loanContract { get; set; }
}
Code in controller
 myList.loanContract = new LoanContract { LoanDateStart = DateTime.Today };
View:
<input disabled type="date" asp-for="loanContract.LoanDateStart" id="dpDateNow" class="form-control" />

It show like this: yyyy-MM-dd what I want to achieve is that I want to change it to MM/dd/yyyy. I tried using .ToString("MM/dd/yyyy") but it doesn't work.



0 comments:

Post a Comment

Note: only a member of this blog may post a comment.