I am building a JIT spacetree like below: http://philogb.github.io/jit/static/v20/Jit/Examples/Spacetree/example1.html
I need to build dynamic Json for it using data coming from database table in MVC.
Currently I called a ActionResult as follows:
var url = "@Url.Action("BinaryTreeData", "Dashboard")";
$.post(url, {}, function (data, status) {
var json1 = $.parseJSON(data.html);
alert(json1.bar);
});
How can I build dynamic Json in ActionResult and can assign it to tree?
Use jquery ajax method and specify json as type for the expected answer. On the server side you can return JsonResult or use the javascript serializer in more generic manner, possibly even defining your own action result (which may be useful depending on what else you will need to do). The serializers in .NET are capable of serializing various object grafs through different types, but this all depends on the structure of the extracted data from database (I cannot guess wxactly what you have there). Still, I think you can start this road and find most answers in the documentation, but be careful - the .NET JSON serializers have some specifics in the gray JSON areas (like datetime formats).