Search code examples
asp.net-mvc-4kendo-asp.net-mvckendo-multiselect

MVC | Telerik | Kendo UI | How to set the .Value via Javascript


Can anyone help me out to dynamically set the Value Property of the Kendo UI Multiselect. I need to show multiple values in this If i have a single item like .Value("1") will show the selected item in the Control but what if i want to pass multiple values like .Value(["1","2"])

I have the List of Ids separated by comma but when i pass this value to the .Value property it doesn't show any selected item.

How i can achieve this using JavaScript.

The below code doesn't work

var vardata = "1,2";
$("#TestPoints").data("kendoMultiSelect").value(vardata);

Solution

  • The following action did the trick, i dont know if this is actually what we have to do it but the below code worked I created a list of all the Values as s string like, in javascript

    var vardata = '[' + Comma Seperate Values likem 1,2 + ']'; 
    e.g. vardata = '[1,2]' 
    

    Later, i parsed the data to JSON and supplied to the .Value() property of kendoui Multiselect

    $("#TestPoints").data("kendoMultiSelect").value(JSON.parse(testpointids)); 
    

    This is done on .cshtml page using javascript.