C# 显示格式、数据格式字符串不适用于电话号码
在我的模型中,我希望能够以111-222-1234的格式显示电话号码,但无法使用dataFormatString获得所需的结果C# 显示格式、数据格式字符串不适用于电话号码,c#,asp.net-mvc,C#,Asp.net Mvc,在我的模型中,我希望能够以111-222-1234的格式显示电话号码,但无法使用dataFormatString获得所需的结果 [Display(Name = "Home Phone")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:999-999-9999}")] public string homePhone { get; set; } 我试着用0和#代替9,但什么也没发生。我可以
[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”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“Property”(是否缺少using指令或程序集引用?)
似乎只有当属性的类型为long-而不是string时,它才起作用