Hi mukesh1,
Make class and property and assigned your arrays value.
Refer below sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnGet").click(function () {
var array = {};
var customer = [];
var obj = {};
obj.Id = 1;
obj.Name = "Robert";
obj.Country = "Russia";
customer.push(obj);
obj = {};
obj.Id = 2;
obj.Name = "Mudassar Khan";
obj.Country = "India";
customer.push(obj);
array.array = customer;
array.arrayindex = $.trim(8);
array.agent_id = $.trim(1);
$.ajax({
type: "POST",
url: "Default.aspx/AllotservicetoAgent",
data: JSON.stringify(array),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: function (response) {
alert(response.d);
},
failure: function (response) {
alert(response.d);
}
});
function OnSuccess(response) {
alert(response.d);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button Text="Submit" runat="server" ID="btnGet" />
</div>
</form>
</body>
</html>
Code
C#
[System.Web.Services.WebMethod]
public static string AllotservicetoAgent(List<myArray> array, int arrayindex, int agent_id)
{
return "Hello "+ arrayindex + Environment.NewLine + "The Current Time is: " + DateTime.Now.ToString();
}
public class myArray
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
}
VB.Net
<System.Web.Services.WebMethod>
Public Shared Function AllotservicetoAgent(ByVal array As List(Of myArray), ByVal arrayindex As Integer, ByVal agent_id As Integer) As String
Return "Hello "& arrayindex & Environment.NewLine & "The Current Time is: " + DateTime.Now.ToString()
End Function
Public Class myArray
Public Property Id As Integer
Public Property Name As String
Public Property Country As String
End Class
Screenshot