I have one array which contain value in following format
var checkedvalue = [];
var x = "230";//Just now constant value pass
var y = "450";
checkedvalue.push({
xCordi : x,
yCordi : y,
bPart:txtName.value
});
in my code i have two button, 1 for push the TEXTBOX data in my array.
Now on second button click i want to pass this value to my web method and perform operation.
$AddtoDB.on('click', function () {
if ( $("#<%= divdynamicData.ClientID %>").is(':empty')){
alert("No Data Found");
}
else{
var ImageName="test.jpeg";
var ImagePath ="c:\drive";
IndertIntoDB(ImageName,ImagePath,checkedvalue);
}
});
the function is called when there is data.
function IndertIntoDB(ImageName,ImagePath,checkedvalue){
//alert(ImageName);
//alert(ImagePath);
//$.each( checkedvalue, function( key, value ) { alert( value.xCordi + ": " + value.yCordi +":"+ value.bPart );});
$.ajax({
type: "POST",
url: "ImageHotSpot.aspx/GetSaveData",
data: JSON.stringify({ iName: ImageName,iPath:ImagePath,iData:checkedvalue }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("DataInserted");
}
});
Now i want to iterate the checkarray in web method but i got error.
//}
[System.Web.Services.WebMethod]
public static void GetSaveData(string iName, string iPath, string[] iData)
{
}
iDatawhich is an array of a js object and not an array of strings. Fix this and yourpost requestwill work.var checkedvalue = [];pushan anonymous object with three propertiesxCordi,yCordi,bPart. So you need a similar object in C# with the same three properties. The name of the class in C# is irrelevant but the three properties should be the same name. Then c# will be able to deserialize your object.