i have reached this page looking for displaying JSON data received via
ASP.NET MVC Action method. The JSON data received via AJAX call was being displayed as a only node of the tree. It was suspected that the data sent as JSON is being treated as HTML which matches with @Martin's remarks related to Content-Type.
Before proceeding with his approach, I just changed the return data from JsonResult to string and strangely, it was displayed properly.
I am sharing the screenshot for feedback + further reference if anyone else reaches here.
@Ivan, nice job man and thumbs up for maintaining + supporting the project for soo long....
screenshots of the network profiler:
JSON Type Response Header:
Test Type Response Header:
[ for the same data, the content-length get reduced for the String type ]
And here is the Controller code:
public JsonResult CustomerList(int projId, int userId)
{
var lvlObj = new LevelTree();
// variable used for readability
var result = lvlObj.GenerateTreeJson(db, 1, 1);
return Json(result, JsonRequestBehavior.AllowGet);
public String GetTreeJson(int projId, int userId)
{
var lvlObj = new LevelTree();
return lvlObj.GenerateTreeJson(db, projId, userId);
}
Finally the script of Tree:
$('#treeView').jstree({
'core': {
'data': {
type: "POST",
cache: false,
url: '/Template/GetTreeJson',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ projId: 1, userId: 1 }),
dataType: 'json',
success: function (node) {
},
error: function (msg) {
alert("Error: " + msg.responseText);
}
}
}
});
[ the call to the action returning JsonResult is not included in the code ]