views:

726

answers:

3

Hi,

Using the jQuery Validation plugin and AJAX, how can I validate the contents of say an input (textbox) but pass more than one parameter to a controller action?

A brilliant example of passing a single value via AJAX using the plugin can be found here.

A: 

Something like this?

$(document).ready(function(){
  $("#form-sign-up").validate( {
    rules: {
      email: {
        required: true,
        email: true
      },
      surname: {
        required: true,
        surname: true
      }
    },
    messages: {
      email: {
        required: "Please provide an email",
        email: "Please provide a valid email"
      },
      surname: {
        required: "Please provide a surname",
        surname: "Please provide a valid surname"
      }
    }
  });
});

edit found a large demo here

adam
The problem I have is that based on the user-name and the value of a hidden field goes into making a unique pair. So when validating the login name I need to pass both the login name and the hidden field value to an action. If you check the example in the question you'll see what I mean.
Kieron
+2  A: 

Looking at the code for jQuery Validation it looks like the post data can not be customized. So you'll have to stick with query parameters:

 <script type="text/javascript">
$(document).ready(function(){
  $("#form-sign-up").validate(
  {
    var param1 = $('#mytextbox').val();

    rules:
    {
        login:
        {
          required: true,
          remote: '<%=Url.Action("IsLoginAvailable", "Accounts") %>?param1=' + param1
        }
      }  
    });

});
</script>
Todd Smith
A: 

The correct Script will be

remote: function() { var p = $j('#productName').val(); return "../Product/LookupRevision?p=" + p; } instead of

remote: "../Product/LookupRevision"

Sumanta