DisplayFormat DataFormatString无法与EditorFor MVC一起使用

时间:2017-03-29 22:53:18

标签: asp.net-mvc data-annotations

我是MVC新手,我正在尝试在显示和编辑模式下格式化电话号码。我在电话号码上使用以下数据注释:

date:2017-03-11
c=1, d=1, e=0

date:2017-03-05
c=6, d=5, e=1

在视图中,我有:

        [Phone]
        [Display(Name = "Work Phone")]
        [DisplayFormat(DataFormatString = "{0:###-###-####}", ApplyFormatInEditMode = true)]
        public string WorkPhone { get; set; }

根据我的理解,这应该可行,但电话号码未在显示或编辑模式下格式化。我也在视图中尝试了以下内容:

 @Html.EditorFor(model => model.WorkPhone, new { htmlAttributes = new { @class = "form-control" } })

但这也不起作用。我错过了什么?任何帮助将不胜感激。

0 个答案:

没有答案
相关问题