gpt4 book ai didi

asp.net-mvc - 电话号码或社会保险号的 DisplayFormat.DataFormatString

转载 作者:bug小助手 更新时间:2023-10-28 10:48:16 25 4
gpt4 key购买 nike

有没有一种方法可以使用 View 模型属性上的 DisplayFormat 属性来为社会安全号码或电话号码应用 DataFormatString 格式?我知道我可以使用 javascript 来做到这一点,但如果可能的话,我更愿意让模型来处理它。

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "???????")]
public string Ssn { get; set; }

最佳答案

以下应该可以工作,但请注意 Ssn 属性的类型差异。

[DisplayFormat(DataFormatString = "{0:###-###-####}")]
public long Phone { get; set; }

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:###-##-####}")]
public long Ssn { get; set; }

请注意,为了应用格式,您需要在 View 中使用以下 html 帮助器:

@Html.DisplayFor(m => m.Property)

关于asp.net-mvc - 电话号码或社会保险号的 DisplayFormat.DataFormatString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10981049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com