Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 隐藏一种验证程序类型而不是另一种MVC3的错误消息_Asp.net_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

Asp.net 隐藏一种验证程序类型而不是另一种MVC3的错误消息

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

是否可以让ValidationMessageFor helper仅显示字段验证程序之一的错误消息。例如,如果我的模型中有这样一个字段:

[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 = "";
    }
}

我曾考虑过一个定制的验证器,但希望有一个更优雅的解决方案来解决真正的配置问题,而不是实现问题。然而,代替任何其他建议,它被接受了!