c# - Deserialization with Newtonsoft.Json -


i have controller, can send json object , recieve same object again. problem ajaxsavefoo creates foo object empty object back. how create deserialization?

/// <summary> /// returns foo /// </summary> /// <returns></returns> public jsonnetresult ajaxloadfoo() {     return new jsonnetresult     {        data = new foo()     }; }  /// <summary> /// saves foo /// </summary> /// <returns></returns> public jsonnetresult ajaxsavefoo(foo foo) //who tries deserialize this!!, empty {      return new jsonnetresult     {         data = foo     };  } 

my client side..

$.ajax({     type: "post",     url: "ajaxsavefoo",     data: json.stringify(this._fooobj),     success: this.savesucces,     datatype: "json",     contenttype: "application/json; charset=utf-8",     error: this.savefailure }); 

foo when sent down..
{

"customernumber": 2, "customerstatus": "1" } 

foo when submitted (post)

{"customernumber":2,"customerstatus":"1"} 

the object passing not getting transformed foo object correctly.

try changing signature input string , try , deserialize:

public jsonnetresult ajaxsavefoo(string json) {    var foo = jsonconvert.deserializeobject<foo>(json);    return new jsonnetresult    {       data = foo    }; }  

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -