Actually I have a Array declared on JS side like below:
var benefArray = {};
var benefCount = 0;
var benefNome = $('#txtBenefNome').val();
var benefDataNasc = $('#txtBenefDataNasc').val();
var benefGrauParent = $('#txtBenefGrauParent').val();
benefCount++;
benefArray[benefCount] = new Array(benefNome, benefDataNasc, benefGrauParent);
//Ajax Sender
function sendAjax(url, parametros, sucesso) {
$.ajax({
type: "POST",
url: url,
data: parametros,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: sucesso
});
};
sendAjax("Client.aspx/AddClient", "{benefArray: \"" + benefArray + "\"}",
function (msg) {
var retorno = msg.d;
alert(retorno);
});
On my C# WebMethod side I Have:
[WebMethod]
public static string AddClient(object benefArray)
{
var t = benefArray;
}
I'm trying to get those values from Javascript, what I have to do? Any insight on this will be appreciated! Thanks
benefArrayisn't an array. It's an object. Each of the members you're assigning to it (benefArray[benefCount] = new Array(benefNome, benefDataNasc, benefGrauParent);) is an array. Granted the distinction is a bit subtle in JavaScript as JavaScript arrays aren't really arrays, but serializers will tend to look at the type to see if it's an array when making serialization decisions, so the distinction could make a difference to what you're doing...