I was not able to get the JSON array parameters in web api controller method (SaveDetails).
Here are my code.
JavaScript Code:
$.ajax( { url : "api/Test/SaveDetails", type : "POST", data : { "employees": [ { "firstName": "John", "lastName": "Doe" }, { "firstName": "Anna", "lastName": "Smith" }, { "firstName": "Peter", "lastName": "Jones" } ] }, success: function (data) {alert("success");}, error: function () {alert("Error");} })
Controller method
[HttpPost]
public DataSet SaveDetails(Models.Person[] obj)
{
//save opertion.
}
Model Method:
public class Person
{
public string firstName { get; set; }
public string lastName { get; set; }
}
What are the changes to be made to get the JSON array parameters in web api method.
[FromBody]
attribute. – Sublunar