Hi Frds,
i hav a problm in passing multiple values frm jquery to c# web method
i'm using chosen plug in any 1 help me
How to pass multiple values fm jquery ajax to C# web methd?
6 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 2, 2013, 9:46 PM EDT
Please share your code.
Arun B11 pointsPosted Sep 2, 2013, 9:56 PM EDT
$(document).ready(function () {
$("#btn_advancedSearch").click(function () {
var test = [];
var j = 0;
$('#Listbox_Marital :selected').each(function (i, selected) {
test[j] = $(selected).val();
j++;
});
$.ajax({
url: "Default.aspx?test=" + test + "",
//url: "Default.aspx/MaritalStatus",
//data: JSON.stringify(f),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
});
});
Arun B11 pointsPosted Sep 2, 2013, 9:59 PM EDT
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 2, 2013, 10:12 PM EDT
You just combine the multiple values with a comma as separator in your data param while ajax operation like:
data:{maritalStatus:'Divorced,Never Married,etc,etc'}
that's it.
You can then split the values at server and process them, how's that?
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 2, 2013, 10:22 PM EDT
Sunny SharmaRank #223 · 11.1K pointsPosted Sep 3, 2013, 2:31 AM EDT
At server side code, just get the data and split it, like:
string[] AllSelectedOptions = receivedString.split(",");
There you go.
I hope it makes sense.
Happy Coding :)
2 short replies
Arun B11 pointsPosted Sep 2, 2013, 10:15 PM EDT
Arun B11 pointsPosted Sep 2, 2013, 10:23 PM EDT