3

I want to use EasyUI jquery tree. So I create a class to use with this jquery tree.

Jquery Tree Data Format Example

[{  
    "id":1,  
    "text":"Folder1",  
    "iconCls":"icon-save",  
    "children":[{  
        "text":"File1",  
        "checked":true  
    },{  
        "text":"Books",  
        "state":"open",  
        "attributes":{  
            "url":"/demo/book/abc",  
            "price":100  
        },  
        "children":[{  
            "text":"PhotoShop",  
            "checked":true  
        },{  
            "id": 8,  
            "text":"Sub Bookds",  
            "state":"closed"  
        }]  
    }]  
    },{  
    "text":"Languages",  
    "state":"closed",  
    "children":[{  
        "text":"Java"  
    },{  
        "text":"C#"  
    }]  
}]

MY MODEL

public class MetersTreeNode
{
    public int id { get; set; }
    public string text { get; set; }
    public string state { get; set; }
    public bool checked { get; set; } //I cant define.
    public string attributes { get; set; }
    public ICollection<MetersTreeNode> children { get; set; }
}

CONTROLLER (maybe this is not neccesary)

public ActionResult GetDemoTree()
{

    var result = new[]
    {
        new MetersTreeNode{
            id = 0,
            text = "level 1",
            state = "open",
            attributes = "",
            children = new[]{
                new MetersTreeNode{
                    id=1,
                    text="level 2",
                    state="open",
                    attributes=""
                },
                new MetersTreeNode{
                    id=2,
                    text="level 2",
                    state="open",
                    attributes="",
                    children = new []{
                        new MetersTreeNode{
                            id=5,
                            text="level 3",
                            state="open",
                            attributes=""
                        }
                    }
                },
                new MetersTreeNode{
                    id=3,
                    text="level 2",
                    state="open",
                    attributes=""
                },
                new MetersTreeNode{
                    id=4,
                    text="level 2",
                    state="open",
                    attributes=""
                }
            }
        }
    };

    return Json(result, JsonRequestBehavior.AllowGet);
}

to use checked parameter. I should define it in my model. But I cant define it. (Error :"invalid token 'checked' in class struct or interface member declaration"). How can I do this. Or if it is not possible, another way to achive that what I want.

Thanks.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197

1 Answers1

9

Please use:

public bool @checked { get; set; }

checked is a reserved C# keyword.

Jay
  • 56,361
  • 10
  • 99
  • 123
petro.sidlovskyy
  • 5,075
  • 1
  • 25
  • 29