我有我的模型:
[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"
,但我得到“The Name field is required.”。
我错过了什么?为什么我收到默认消息?
PS:我不知道是否有任何区别,但我正在使用服务器端验证(ModelState)。
更新
在同一个模型中,我使用了Required
(来自 .Net 的本机),并且Required
运行良好。但一切 RequiredIf
都没有。