[Required(ErrorMessage = "ONLY TYPE IN NUMBERS!")]
[Display(Name = "Telefono Fijo")]
public int Telephone { get; set; }
基本上,我希望当有人输入一个字母时,上面的文本应该显示出来。
这是我的观点:
<div>
@Html.LabelFor(model => model.RegisterModel.Telephone)
@Html.EditorFor(model => model.RegisterModel.Telephone)
@Html.ValidationMessageFor(model => model.RegisterModel.Telephone)
</div>
当我输入字母时,我得到:
"The field Telefono Fijo must be a number."
当我不输入任何东西时,我得到:
"ONLY TYPE IN NUMBERS!"
任何想法?我只想显示自定义消息
你应该使用regulareexpression attribute:
[RegularExpression(@"^d+$", ErrorMessage = "ONLY TYPE IN NUMBERS!")]