Monday, November 4, 2013

Remote validation using jQuery Validate

This is how jQuery validate is done in ASP.NET MVC

<form id="manager-form" action="">
        <label style="display:inline-block; width: 200px;">Manager Name</label>
        <input type="text" id="Manager" name="Manager" />
        <input type="submit" id="saveManager" class="btn btn-primary" value="Save Sales Person" />
    function SetValidationRules(){
            onkeyup: false,
            rules: {
                Manager: {
                    required: true,
                    minlength: 3,
                    remote: {
                        url: '/Manager/IsManagerNameTaken',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            managerName: function () {
                                return $('#Manager').val();
            messages: {
                Manager: {
                    required: "Manager name is required.",
                    minlength: "Manager name should be 3 atleast characters."
    public ActionResult IsManagerNameTaken(string managerName)
        var result = ManagerRepository.IsManagerNameTaken(managerName) ?
            "Manager name is already taken. Try another!" : "";
        return Json(result);
Thats all to it. Happy coding!

Related Posts :

0 comments on "Remote validation using jQuery Validate"

Add your comment. Please don't spam!
Subscribe in a Reader

Post a Comment