Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting values in Kendo UI multiselect
    primarykey
    data
    text
    <p>I've run into some trouble and have not bee able to find an answer for this particular problem. I have a multiselect from kendo need it to per-populate it's values when I have an ID provided. In the view I check if I have the ID in the query string</p> <pre><code>$(function () { if (visitationID != "") { var visitationIDs = $.getJSON('/Visitation/GetVisitationTypesByID', { id: visitationID }, 'json'); $("#visitTypeMulti").data("kendoMultiSelect").value(visitationIDs); } }); </code></pre> <p>and how I'm declaring the multiSelect</p> <pre><code>&lt;div id="visitTypeDiv"&gt; &lt;label&gt;Visit Type: &lt;/label&gt; &lt;input id="visitTypeMulti" /&gt; &lt;/div&gt; var visitTypes = $("#visitTypeMulti").kendoMultiSelect({ placeholder: "Select a visitation type...", dataTextField: "VisitationType", dataValueField: "VisitationTypeID", autoBind: false, filter: "contains", dataSource: { type: "json", serverFiltering: true, transport: { read: "/Visitation/GetVisitationTypes", dataType: "json" } }, highlightFirst: true, ignoreCase: true }); </code></pre> <p>and lastly the controller code that returns the visitIDs in an array. I'm using an existing query and then removing the text so it is returning an array of only the ID (integers) I know they need to be strings so I force them into a string array.</p> <pre><code>public ActionResult GetVisitationTypesByID(int id) { VisitationDetailsModel model = new VisitationDetailsModel(); var rawData = model.RetrieveVisitationTypes(id); //now gurantee I strip out the Airport visitation string[] visitTypes = rawData.Select(x =&gt; x.VisitationTypeID.ToString()).ToArray(); return Json(visitTypes, JsonRequestBehavior.AllowGet); } </code></pre> <p>When I set the value I see no change but if I change it to hard-coded values <code>$("#visitTypeMulti").data("kendoMultiSelect").value(["1","5"]);</code> It works just fine. Also if I try a JSON.Parse() on the visitationIDs I get an error. I did check the JSON return and it is the same data in the hard coded example ["1","5"]. What am I doing wrong/how do I format the data in such a way that Kendo UI is going to take it? Thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload