Reputation: 6725
I have an Kendo MultiSelect which uses ajax to grab the select menu potential values from a database table that is not directly related to the model.
MultiSelect:
@(Html.Kendo().MultiSelect()
.Name("ContactTags")
.DataTextField("Name")
.DataValueField("TagId")
.Placeholder("Please select a tag")
.AutoBind(false)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetTags", "ContactTag");
})
.ServerFiltering(true);
})
)
The above code with render the Select Menu and post the data back to the controller where I can parse it and send it to the database. That all works when creating a new tag. The problem arises when there are already existing tags on an entity. How do I make Kendo get the existing tags and mark them as selected in the Multiselect menu.
Upvotes: 0
Views: 60
Reputation: 12304
Build a list of the selected items in the controller action that calls this view and it to your Model (ViewModel).
Then add a .Value() clause to the widget:
@(Html.Kendo().MultiSelect()
.Name("ContactTags")
.DataTextField("Name")
.DataValueField("TagId")
.Placeholder("Please select a tag")
.AutoBind(false)
.Value(Model.SelectedTags)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetTags", "ContactTag");
})
.ServerFiltering(true);
})
)
Upvotes: 1