开发者

failing in JSON MVC Controller binding

In my MVC3 RC2 appplication, I am retrieving the tree structure from JsTree using its JSON_DATA plugin's get_json() call and using an Ajax call back to an Action method in my controller.

[HttpPost]
public virtual ActionResult JsTreeTest(List<JsTreeNode> jsTreeNodes)
{
    // convert passed POCO back to JSON for debugging/comparison
    string json = JsonHelper.Serialize(jsTreeNodes);

    // convert JSON to POCO for debugging/comparison
    List<JsTreeNode> r = JsonHelper.Deserialize<List<JsTreeNode>>(json);

    return View(MVC.Home.JsTreeTest());
}

My JsTreeNode class definition is as follows:

[DataContract]
public class JsTreeNode
{
    [DataMember]
    public NodeAttributes attr { get; set; }

    [DataMember]
    public Data data { get; set; }

    [DataMember]
    public string state { get; set; }

    [DataMember]
    public List<JsTreeNode> children { get; set; }
}

This works 100% OK -- but to avoid confusion, I want to rename the "attr" property to "nodeAttributes", so I changed my class definition as follows:

[DataContract]
public class JsTreeNode
{
    [DataMember(Name = "attr")] 开发者_JS百科                       // Expecting name "attr" in JSON
    public NodeAttributes nodeAttributes { get; set; } // Store the "attr" value here

    [DataMember]
    public Data data { get; set; }

    [DataMember]
    public string state { get; set; }

However, now the passed value of nodeAttributes is always "null".

I am sure I am missing something obvious or completely fail to understand the correct usage of the "Name" attribute.

Any advice would be much appreciated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜