Why is DisplayFormat DataFormatString not working?

前端 未结 8 749
名媛妹妹
名媛妹妹 2020-11-29 05:27

I have a property in my view model as follows:

[Editable(false)]
[Display(Name = \"Date\")]
[DisplayFormat(DataFormatString = \"{0:yyyy/MM/dd}\", ApplyFormat         


        
相关标签:
8条回答
  • 2020-11-29 05:57

    You have to annotate the type as Date

    [DataType(DataType.Date)]
    
    0 讨论(0)
  • 2020-11-29 05:57

    I had a similar issue with a datepicker which was showing the date in the wrong order. Fixed it by using the HTML 5 value field. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

    <input asp-for="From" type="text" class="pickadate picker__input" value="@Model?.From.ToString("MM/dd/yyyy")">
    
    0 讨论(0)
提交回复
热议问题