I am referring this article:
http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx
which shows how to create custom annotation in Asp.Net MVC 2
The key thing missing here is that the server-side validator must implement the IClientValidatable interface:
public class RateRequiredIfCustomIndexRateAttribute : ValidationAttribute, IClientValidatable
{
public override bool IsValid(object value)
{
return false;
}
public IEnumerable GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
yield return new ModelClientValidationRule
{
ErrorMessage = this.ErrorMessage,
ValidationType = "raterequiredifcustomindexrate"
};
}
}
Once you do that, the client-side validation should be hooked up properly. You can verify this by making sure that your input field has an attribute "data-val-raterequiredifcustomindexrate" attribute.