Take the 2-minute tour ×

I have a field that has required validation property and also remote validation property.

I want to display the error message only if remote validation fails, and not on required property.

I can set the error message to an empty string, but i don't want to modify the ViewModel Data Annotations.

Is possible to do this only from client-side, without modifying the ViewModel properties?

// working hack
public class CreateViewModel
    [Required(ErrorMessage = " ")]
    [Remote("IsUserNameValid", "Users", ErrorMessage = "This user name is already used")]
    [Display(Name = "User Name")]
    public string UserName { get; set; }
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could disable the required rule. For example given a form with id "LoginForm" and a required input field with id "UserName", you can disable the required rule using either of these:

$("#UserName").rules("remove", "required");
$("#loginForm").validate().settings.rules["UserName"].required= false;

Another option is to change the error message to an empty string. Again you have a few options, for example:

$("#UserName").rules("add", {
    messages: {
        required: ""
$("#loginForm").validate().settings.messages["UserName"].required= '';

In the end this is about playing with the rules and messages of the jquery validation object for the form.

Hope it helps!

share|improve this answer
add comment

Your Answer


