开发者

Hiding error message for one validator type but not another MVC3

开发者 https://www.devze.com 2023-02-22 16:11 出处:网络
开发者_开发技巧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:

开发者_开发技巧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...


I know it's ugly but this will work

public class CustomeRequired : RequiredAttribute
{
    public CustomeRequired()
    {
        this.ErrorMessage = "";
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号