I hope you have read the initial part of this post here.
5. Lesson i have learned the hard way is, If we are dealing with complex objects a mix of array and complex object. Make sure the property name of the javascript class and .Net class is exactly same.
For instance if the JavaScript content is
function jsonmenuwrapper(menu) { this.menu = menu; } function jsonmenu(id,value,popup) { this.id = id; this.value = value; this.popup = popup; } function jsonpopup(menuitem) { this.menuitem = menuitem; } function jsonmenuitem(value,onclick) { this.value = value; this.onclick = onclick; } var myjsonmenuitem = []; myjsonmenuitem[0] = new jsonmenuitem("value","onclickMain"); myjsonmenuitem[1] = new jsonmenuitem("value1","onclickSub"); var myjsonpopup = new jsonpopup(myjsonmenuitem); var myjsonmenu = new jsonmenu("1", "Reports", myjsonpopup); var myjsonmenuwrapper = new jsonmenuwrapper(myjsonmenu);
The C# class must have class like
public class JsonPopup { public Menuitem menuitem {get; set;} } function jsonpopup(menuitem) { this.menuitem = menuitem; }
The property name in the class must be same in both JavaScript and C#.
1 comment