我的模型中声明的 MVC3 错误消息未生效
[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!"
有什么想法吗?我只想显示自定义消息。
[Required(ErrorMessage = "ONLY TYPE IN NUMBERS!")]
[Display(Name = "Telefono Fijo")]
public int Telephone { get; set; }
Basically, I'd like that when someone types in a letter, that text up there should display.
Here's my view:
<div>
@Html.LabelFor(model => model.RegisterModel.Telephone)
@Html.EditorFor(model => model.RegisterModel.Telephone)
@Html.ValidationMessageFor(model => model.RegisterModel.Telephone)
</div>
When I type in letters, I get:
"The field Telefono Fijo must be a number."
And when I don't type in ANYTHING, I get:
"ONLY TYPE IN NUMBERS!"
Any ideas? I only want the custom message to show.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 RegularExpressionAttribute:
You should use RegularExpressionAttribute: