Json Data between UI and handler continued…

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#.
Advertisement

1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: