Reputation: 484
I tried many ways to do it but everytime ajax send null to controller. I have json object array like as following style. I would like to send this array to my controller but every time controller parameter is null. What am i doing wrong ?
{
"barkodliste":[
{
"ToplamSonuc":0,
"KitapKey":12,
"DemirbasNo":112,
"Isbn":"fghfgh",
"KutuphaneSiraNo":"fghfghh/fghfg",
"KitapAdi":"0000000000112 - Fghfg",
"Adet":0,
"Durum":1
},
{
"ToplamSonuc":0,
"KitapKey":15,
"DemirbasNo":115,
"Isbn":"sdlfkjsd",
"KutuphaneSiraNo":"fsdkljflskdj/dsfkl",
"KitapAdi":"0000000000115 - Sdlfkjsd",
"Adet":0,
"Durum":1
}
]
}
KitapAramaSonucModel.cs
public class KitapAramaSonucModel
{
public int ToplamSonuc { get; set; }
public int KitapKey { get; set; }
public int DemirbasNo { get; set; }
public string Isbn { get; set; }
public string KutuphaneSiraNo { get; set; }
public string KitapAdi { get; set; }
public string Yazar { get; set; }
public int Adet{ get; set; }
public int Durum { get; set; }
public string Barkod { get; set; }
}
Controller
[HttpPost]
public async Task<JsonResult> BarkodBasilacakKitaplariGetir(List<KitapAramaSonucModel> barkodlar)
{
//Do something with barkodlar
}
cshtml
var barkodliste = $("#books").data("kendoMultiSelect").dataItems();
$.ajax({
cache: false,
url: "/Kutuphane/BarkodBasilacakKitaplariGetir",
type: 'POST',
contentType: "application/json charset=utf-8",
traditional: true,
data: JSON.stringify({ barkodlar: barkodliste }),
success: function (data) {
alert("success");
}
});
Upvotes: 0
Views: 1040
Reputation: 470
Your controller is waiting for:
[
{
"ToplamSonuc":0,
"KitapKey":12,
"DemirbasNo":112,
"Isbn":"fghfgh",
"KutuphaneSiraNo":"fghfghh/fghfg",
"KitapAdi":"0000000000112 - Fghfg",
"Adet":0,
"Durum":1
},
{
"ToplamSonuc":0,
"KitapKey":15,
"DemirbasNo":115,
"Isbn":"sdlfkjsd",
"KutuphaneSiraNo":"fsdkljflskdj/dsfkl",
"KitapAdi":"0000000000115 - Sdlfkjsd",
"Adet":0,
"Durum":1
}
]
Upvotes: 0