c# - Controller not receiving Json -


i can work. have sending json js file controller controller receive null object.

this js:

 var myjson2 = json.stringify(resultitems);              console.log(myjson2);              $.ajax({                   url: "/mainmap/receivegeoid",                  type: "post",                  data: myjson2,                  contenttype: "application/json; charset=utf-8",                  datatype: "json",                  error: function (response) {                      alert("error");                  },                  success: function (response) {                      alert("success");                  }               }); 

and json when debug program:

enter image description here

my model looks this:

  public class censusmodellist {     public list<censusreceive> censuslist { get; set; }  }  public class censusreceive {     string geoid { get; set; }  } 

and controller looks this:

  [httppost]     public actionresult receivegeoid(censusmodellist censusdata)     {         var test = censusdata;         return view();      } 

is seem cannot json:

enter image description here

thank much!

your model wrong, if @ json you're receiving array of items, model expects single object contains property named censuslist array of censusreceived, deserialization results in null object because not match.

the easiest way fix change function this:

public actionresult receivegeoid(censusreceive[] censusdata) 

in case model match received data.

also, geoid property must public or deserializer not find , null.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -