c# - JSON not being deserialized correctly on the server -


i have javascript object on client-side has settingname , settingvalue properties.

data examples -

obj1.settingname = "createddate"; obj1.settingvalue = "10/07/2013";  obj2.settingname = "arrayofnames"; obj1.settingvalue = somearray; //an array of 5 strings  var settingsarray =new array(); settingsarray[0] = obj1; settingsarray[1] = obj2;  var settingscontainer = new object; settingscontainer.settings = settingsarray; 

ajax call -

    $.ajax({         type: "post",         url: "myurl",         data: { settings: json.stringify(settingscontainer)},         datatype: 'json',         success: function (data) {             //do         }     }); 

server side class -

public class setting {             public string settingname { get; set; }     public object settingvalue { get; set; } //so can hold multiple data types }  public class settingscontainer  {     public list<setting> settings { get; set;} } 

controller action -

public actionresult myurl(settingscontainer settings) {     //here, value settingscontainer.settings[1].settingvalue,        should array[5] i.e. on c# side, expect see object[5],        {object}. i'm not sure what's going on.        approach of handling correct? } 

any advise/help appreciated. thank-you!

on server side method, should use:

   public actionresult myurl(string settings) {        // deserialize string object here;     } 

but have re-design classes because aren't supported javascript deserialization.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -