Why is DisplayFormat DataFormatString not working?

前端 未结 8 813
名媛妹妹
名媛妹妹 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:41

    This work for me:

    In the model:

    using System.ComponentModel.DataAnnotations;
    
    namespace Athlete.Models
    {
        public class Foo
        {
    
            [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
            public DateTime SignDate
            {
               get;
               set;
            }
        }
    }
    

    And in the view:

    @Html.DisplayFor(modelItem => item.SignDate)
    

提交回复
热议问题