Click here to Skip to main content
15,126,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 'application/json' otherwise data will not be received by the server.:

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 () {
type: 'POST',
url: '/SeedPOSAPITest/SeedPOSAPI/api/POSTransaction',
data: JSON.stringify(list),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
proccessData: false,
success: function (data) {
Jameel VM 26-May-15 15:50pm
you have already set the content type in client and sent to server.Web api will automatically identifies it.then what problem you are facing?
kumar nitesh 27-May-15 2:22am
after adding the content type ie. 'application/json' it will showing cors issue.
Jameel VM 27-May-15 12:38pm
it's not because of content's cross domain issue
Jameel VM 27-May-15 12:40pm
just enable cross domain support in web api

1 solution

Just try this link[^]
Hope this helps

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900