Asp.net 隐藏一种验证程序类型而不是另一种MVC3的错误消息
是否可以让ValidationMessageFor helper仅显示字段验证程序之一的错误消息。例如,如果我的模型中有这样一个字段:Asp.net 隐藏一种验证程序类型而不是另一种MVC3的错误消息,asp.net,asp.net-mvc,asp.net-mvc-3,Asp.net,Asp.net Mvc,Asp.net Mvc 3,是否可以让ValidationMessageFor helper仅显示字段验证程序之一的错误消息。例如,如果我的模型中有这样一个字段: [Required] [Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")] public string Symbol { get; set; } 我不想为req
[Required]
[Remote("SymbolUnique", "RemoteValidation", ErrorMessage = "A document already exists in the database for the entered symbol")]
public string Symbol { get; set; }
我不想为required显示消息,只希望突出显示文本框的视觉指示,而是为远程验证器显示消息。如果我将required属性的ErrorMessage参数设置为空字符串,则会在框架太聪明时同时设置ErrorMessage和ErrorMessageResourceName时出错…我知道这很难看,但这会起作用
public class CustomeRequired : RequiredAttribute
{
public CustomeRequired()
{
this.ErrorMessage = "";
}
}
我曾考虑过一个定制的验证器,但希望有一个更优雅的解决方案来解决真正的配置问题,而不是实现问题。然而,代替任何其他建议,它被接受了!