Using the jQuery validatation plugin to send multiple values to an ASP.NET MVC controller action?
-
22-07-2019 - |
Question
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.
Solution
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>
OTHER TIPS
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
The correct Script will be
remote: function() { var p = $j('#productName').val(); return "../Product/LookupRevision?p=" + p; } instead of
remote: "../Product/LookupRevision"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow