c# - 如何创建一个名为 "checked"的属性?

标签 c# jquery asp.net-mvc jquery-easyui

我想使用 EasyUI jquery tree .所以我创建了一个类来使用这个 jquery 树。

Jquery 树数据格式示例

[{  
    "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#"  
    }]  
}]

我的模型

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(也许这不是必需的)

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);
}

使用checked 参数。我应该在我的模型中定义它。但我无法定义它。 (错误:“在类结构或接口(interface)成员声明中‘检查’了无效的标记”)。我怎样才能做到这一点。或者,如果不可能,另一种实现我想要的方法。

谢谢。

最佳答案

请使用:

public bool @checked { get; set; }

checked是保留的 C# 关键字。

关于c# - 如何创建一个名为 "checked"的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13862283/

相关文章:

asp.net - 在 asp.net MVC 中创建面包屑路径

c# - 将 ActionResult 呈现为字符串 - 输出顺序不正确

javascript - C# MVC AJAX 请求

c# - 取消选择数据 GridView 中的所有行

c# - 从地平线获取一条线的角度

javascript - knockout 完成后运行脚本

php - jquery .eq 不适用于某些导航项目

c# - WebRequest 加载 HTMLDocument 返回 SSL 站点的所有特殊字符

c# - 同一类(class) child 列表之间的映射

javascript - asp.net 服务器端禁用客户端启用的单选按钮