I have a class like
public class Category
{
public int ID { get; set; }
public string Name { get; set; }
public ICollection
The last parameter of the MultiSelectList
constructor takes an array of selected Id
's not a collection of Category
complex types.
If you change it to this instead it will work as expected:
product.Categories = new MultiSelectList(list, "ID", "Name", cat.CategorySelected.Select(c => c.ID).ToArray());
It simply projects it into an array of Id
's instead.
See below screen shot:
Ps I also had to add this to the constructor of Category
to initialize the collection:
public Category()
{
CategorySelected = new List<Category>();
}