是否可以让ValidationMessageFor帮助程序仅显示字段验证程序之一的错误消息。 例如,如果我的模型中有一个字段,如下所示:
[Required] [Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")] public string Symbol { get; set; }我不希望显示所需的消息,只对正在突出显示的文本框的可视指示感到满意,但显示远程验证器的消息。 如果我将required属性的ErrorMessage参数设置为空字符串,则在设置ErrorMessage和ErrorMessageResourceName时会出现错误,因为框架开始过于聪明......
Is it possible to have a ValidationMessageFor helper only display the error message for one of the field's validators. For example if I had a field in my model like this:
[Required] [Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")] public string Symbol { get; set; }I wouldn't want to show the message for required, being happy with just the visual indication of the textbox being highlighted, but show the message for the remote validator. If I set the ErrorMessage parameter of the required attribute to an empty string I get an error for setting both the ErrorMessage and ErrorMessageResourceName as the framework starts being too clever...
最满意答案
我知道这很丑,但这会奏效
public class CustomeRequired : RequiredAttribute { public CustomeRequired() { this.ErrorMessage = ""; } }I know it's ugly but this will work
public class CustomeRequired : RequiredAttribute { public CustomeRequired() { this.ErrorMessage = ""; } }更多推荐
发布评论