views:

32

answers:

1

Hi,

I'm working on an ASP.Net MVC2 application and use the jsTree-Komponent for jQuery to render a tree with checkboxes.

To select specific nodes in a convenient way my JSON has to offer a "class" attribute. Here's an example how jsTree wants to consume the JSON result:

[{"data":"Root1","attr":{"id":"10","class" : "jstree-checked"} ...

In the controller I use "return Json(tree);" to create the Json and my ViewModel would than need a "class" property. A "class" property isn't allowed in C# as it is a reserved word.

Is there a way to Annotate the ViewModel's attribute as it is with XML? XMLExample:

[XmlAttribute("class")]
public string cssClass = "";

Or are there other suggestions to handle this on the server side?

Cheers, Helmut

A: 

I finally solved this and answer the question on my own. If my description on the topic had been clearer, someone would have probably answered this question a long time ago.

Instead of using the property "class" (which is a reserved key word) you can specify "@class". Here's a small code snippet that works.

var tree = new JsTreeModel[] 
{
new JsTreeModel {
                data = new JsTreeData{title="Root1"},
                attr = new JsTreeAttribute { id="10",@class="jstree-checked" }
            }
}

I have used the @class attribute in different scenarios (e. g. for specifying a css-class in Html.Actionlink) but haven't transfered that knowledge to the JSON example...

agez