c# - ASP.Net Core posting list from ajax to controller -


i able send single complex type ajax controller not able pass list, comes null. *** code has been updated show successful passing.

public class entityaliastest {   public int idtemp1 { get; set; }   public string nametemp1 { get; set; } } 
[httppost] public iactionresult saveentityaliases([frombody]  list<entityaliastest> postdata) {   var es = modelstate.serializeerrors();   return json(new[] { postdata, es }); } 
var aliaslist = new array();  var o = { idtemp1 : 0, nametemp1: 'test 0' }; aliaslist.push(o);  o = { idtemp1 : 1, nametemp1: 'test 1' }; aliaslist.push(o);  o = { idtemp1 : 2, nametemp1: 'test 2' }; aliaslist.push(o);  var postdata= json.stringify(aliaslist);  $.ajax({   url: "dataadministration/entityalias/saveentityaliases",   type: "post",   cache: false,   datatype: "json",   contenttype: "application/json; charset=utf-8",   data: postdata, }).done(function (data) { 

based on ajax call, sending single object contains list. controller expect object kind of structure.

instead of this: var data = { postdata: aliaslist }; var data2send = json.stringify(data);

you can try: var data2send = json.stringify(aliaslist);

you can use online json validator check if pass valid json data. can refer on link below.

https://jsonlint.com/

hope help.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -