I want to send an array of objects in my ajax call and for that i have to use json.stringify and after that i have to set content-type header as
here is the code for web api post method:
public bool Post(object[] list)
{
Newtonsoft.Json.Linq.JObject jObjOfSMaster = (Newtonsoft.Json.Linq.JObject)list[0];
TblSaleMaster obj = new TblSaleMaster();
obj = GetSaleMaster(jObjOfSMaster);
List<tblsalemasterdetail> listSMD = new List<tblsalemasterdetail>();
listSMD = GetSaleMasterDetail(list);
DBTSeedRepository repository = new DBTSeedRepository();
return repository.InsertSale(obj, listSMD);
}
here i am posting data as an arry of objects
$('#btnSubmit').click(function () {
$.ajax({
type: 'POST',
url: '/SeedPOSAPITest/SeedPOSAPI/api/POSTransaction',
data: JSON.stringify(list),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
proccessData: false,
success: function (data) {
alert(data);
}
});
});