Kendo Datasource from json returedn from server Controller

2 posts, 0 answers
  1. Sohel
    Sohel avatar
    4 posts
    Member since:
    Dec 2008

    Posted 25 Nov 2016 Link to this post

    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?

     

     

     

     

     

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1810 posts

    Posted 29 Nov 2016 Link to this post

    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.
Back to Top