This is a migrated thread and some comments may be shown as answers.
Selected values not working
1 Answer 4 Views
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 20 Dec 2020, 11:29 PM

I have a controller with code like this

public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Assembly assembly = db.Assemblies.Find(id);
            var assemblyViewModel = new AssemblyViewModel
            {
                AssemblyId = assembly.AssemblyId,
                Description = assembly.Description,
                AssemblyItemMasterIds = db.AssemblyItems
                    .Where(w => w.AssemblyId == assembly.AssemblyId)
                    .Select(s => s.ItemMasterId)
                    .ToList()
            };

            return PartialView(assemblyViewModel);
        }

 

The view looks like this.

@(Html.Kendo().MultiSelectFor(model => model.AssemblyItemMasterIds)
                    .Name("AssemblyItemMasterIds")
                    .DataTextField("text")
                    .DataValueField("id")
                    .Placeholder("Select Items...")
                    //.AutoBind(false)
                    .DataSource(source => {
                        source.Read(read =>
                        {
                            read.Action("GetItemMasters", "ItemMasters");
                        })
                        .ServerFiltering(true);
                    })
                )

 

I have validated that the model is populated and that AssemblyItemMasterIds does have a list of the id's that should be selected.

If I click on the dropdown, the selected values populate.  Shouldn't they be populating without me having to that?

What am I missing?

 

1 Answer, 1 is accepted

Sort by
0
n/a
Top achievements
Rank 1
answered on 20 Dec 2020, 11:31 PM

I figured it out.  Here is the view code that works.

@(Html.Kendo().MultiSelect()
                    .Name("AssemblyItemMasterIds")
                    .DataTextField("text")
                    .DataValueField("id")
                    .Placeholder("Select Items...")
                    .AutoBind(true)
                    .Value(Model.AssemblyItemMasterIds)
                    .DataSource(source => {
                        source.Read(read =>
                        {
                            read.Action("GetItemMasters", "ItemMasters");
                        })
                        .ServerFiltering(true);
                    })
                )

Asked by
n/a
Top achievements
Rank 1
Answers by
n/a
Top achievements
Rank 1
Share this question
or