[英]display format, data Format String not working for phone number
在我的模型中,我希望能够以111-222-1234的格式显示电话号码,但无法使用dataFormatString获得所需的结果。
[Display(Name = "Home Phone")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:999-999-9999}")]
public string homePhone { get; set; }
我尝试使用0和#代替9,但是什么也没有发生。 只要电话号码不配合,我就可以更改日期。
这应该工作:
[DisplayFormat(DataFormatString = "{0:###-###-####}")]
public long Phone { get; set; }
请注意,为了应用格式设置,您需要在视图中使用以下html帮助器:
@Html.DisplayFor(m => m.Property)
'System.Collections.Generic.IEnumerable'不包含'Property'的定义,也找不到扩展方法'Property'接受类型为'System.Collections.Generic.IEnumerable'的第一个参数(您是否缺少using指令或装配参考?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.