asp.net mvc - Kendo Multiselect: Selected values from binded model are not initialized -


update:

to shorten question:

how bind selectlist kendo ui multiselect widget using razor?

original question:

in asp.net mvc 4 application, trying kendo multiselect working. binding multiselect widget model/viewmodel init values not being used. selecting , works perfectly.

model:

public class data {     public ienumerable<int> selectedstudents{ get; set; } }  public class student {     public int id { get; set; }     public string name { get; set; } } 

controller:

list<student> students = new list<student>(); students.add(new baumaterial { id = 1, name = "francis" }); students.add(new baumaterial { id = 2, name = "jorge" }); students.add(new baumaterial { id = 3, name = "drew" }); students.add(new baumaterial { id = 4, name = "juan" });  viewbag.students= new selectlist(students, "id", "name"); data data = new data { selectedstudents = new list<int>{2, 4} };  return partialview(data); 

view: standard-html works perfectly!!

<div class="form-label">     @html.labelfor(model => model.selectedstudents) </div> <div class="form-field large">     @html.listboxfor(model => model.selectedstudents, (selectlist)viewbag.students) </div> <div class="form-message">     @html.validationmessagefor(model => model.selectedstudents) </div> 

view: kendo multiselect not working --> multiselect empty (no preselections), can select values perfectly

<div class="form-label">     @html.labelfor(model => model.selectedstudents) </div> <div class="form-field large">     @(html.kendo().multiselectfor(model => model.selectedstudents)         .bindto((selectlist)viewbag.students)     ) </div> <div class="form-message">     @html.validationmessagefor(model => model.selectedstudents) </div> 

what doing wrong? advice!

using multiselect() instead of multiselectfor() , pass preselection list of strings instead of list of integers.

@(html.kendo().multiselect()     .name("selectedstudents")     .bindto(new selectlist(viewbag.students, "id", "name"))     .value(model.selectedstudents) ) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -