Remote Validator in Asp.net mvc3 razor


Now the ASP.NET MVC 3 supports the new RemoteAttribute class that enables us to take advantage of the jQuery Validation plug-in's remote validator support.

This enables the client-side validation library to automatically call a custom method that you define on the server in order to perform validation logic that can only be done server-side.
See In the following below example, the Remote attribute specifies that client validation will call an action named UserNameAvailable on the UsersController class in order to validate the UserName field.
public class User  
{ 
    [Remote("UserNameAvailable", "Users")] 
    public string UserName { get; set; } 
}

The following example shows the corresponding controller.
public class UsersController  
{  
    public bool UserNameAvailable(string username)  
    {  
        if(MyRepository.UserNameExists(username))  
        {  
            return "false";  
        }  
        return "true";  
    }  
}
Next Recommended Reading Range Validator In ASP.NET