Hiding error message for one validator type but not another MVC3
开发者_开发技巧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 = "";
}
}
精彩评论