How to call a server side method with custom parameters as inputs via jquery ajax functionality?
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
}
[WebMethod]
public static void AddEmployee(Employee employee)
{
//Some logic
}
In my design I have two textboxes for inputting ID and Name of the employee. On clicking the button I need to invoke the method AddEmployee.
How can I pass the values to the WebMethod AddEmployee via jquery ajax?
Please mention a solution for these kind of scenarios.

Praveen Raveendran PillaiPosted Jun 2, 2014, 3:12 AM
Anupam SinghPosted Jun 2, 2014, 2:55 AM
$.ajax() support a parameter data:
try sending
data: "{Employee:" + JSON.stringify(Employee) + "}",
you can read a brief article here :
http://www.aspsnippets.com/Articles/Send-and-Receive-JSON-objects-to-Web-Service-Methods-using-jQuery-AJAX-in-ASPNet.aspx
Praveen Raveendran PillaiPosted Jun 2, 2014, 2:45 AM
Thanks for the response.
The issue is not solved for me.
How to invoke the method of Custom Data Type?
Method:
public void AddEmployee(Employee employee)
{
//insert logic.
}
I hope you got my question.
Anupam SinghPosted Jun 2, 2014, 2:30 AM
See this article :
http://www.c-sharpcorner.com/UploadFile/63e78b/call-an-Asp-Net-C-Sharp-method-web-method-using-jquery/
Hope will help.