万无一失必需如果错误消息不起作用

时间:2014-09-16 22:44:26

标签: c# .net asp.net-mvc asp.net-mvc-4 foolproof-validation

我的模特有:

[RequiredIfTrue("OtherField", ErrorMessage = "The field {0} cannot be blank")]
[Display(Name = "The Name")]
public string Name { get; set; }

我设置了ErrorMessage然后我希望在验证时,错误消息是"The field The Name cannot be blank",但我得到了#34;“名称”字段是必需的。&# 34。

我错过了什么吗?为什么我收到默认消息?

PS :我不知道是否有任何区别,但我使用服务器端验证(ModelState)。

更新

在同一模型中,我使用Required(来自.Net),Required效果很好。但所有 RequiredIf都没有。

0 个答案:

没有答案
相关问题