This is a migrated thread and some comments may be shown as answers.

Kendo Datasource from json returedn from server Controller

1 Answer 141 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Sohel
Top achievements
Rank 1
Sohel asked on 25 Nov 2016, 06:52 PM

Lets say, I have a model like the following:

public class AssignmentListViewModel
{
    public string JsonAssignmentList { get; set; }

}

Loading the model:

model.JsonAssignmentList = Newtonsoft.Json.JsonConvert.SerializeObject(assignmentList.Assignments);

On the client when I create new kendo.data.TreeListDataSource, I try to do the following and get error

"SCRIPT1028: Expected identifier, string or number"

var json = JSON.parse(@Model.JsonAssignmentList);
var dataSource = new kendo.data.TreeListDataSource({
@*data: JSON.stringify(@Model.JsonAssignmentList),*@
data: json,
            
// Enable batch updates
batch: true,
// Define the model schema
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", editable: false, nullable: false },
parentId: { from: "ChildAssignmentListId", type: "number", defaultValue: 0 },
Step: { validation: { required: true } },
AssigneeDisplayName: { validation: { required: true } },
Description: { validation: { required: true } },
Status: { validation: { required: true } },
StatusText: { validation: { required: true } },
Instructions: { validation: { required: false } },
//Deadline: { validation: { required: false } },
DeadlineDueDateText: { validation: { required: false } }
}
}
}
});

 

How can I return json string from the controller and bind it to a kendo treelist?

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 29 Nov 2016, 12:59 PM

Hello Sohel,

The easiest way to determine what might be the problem in your case is to compare your data with an example that works fine. For example please refer to the example below the autoBind article of the Kendo UI TreeList. The value for the data field of the DataSource is simply array of JavaScript objects with key value pairs. 

Regards,
Boyan Dimitrov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
TreeList
Asked by
Sohel
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or