1

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")]                        // 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.

JcMaltaDev
  • 1,344
  • 1
  • 9
  • 17
  • Similar to [this post](http://stackoverflow.com/questions/6020889/asp-net-mvc-3-controller-json-method-serialization-doesnt-look-at-datamember-na) – Fatih Türker Jun 28 '11 at 14:00

0 Answers0