I got compiling error below:
Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'
Argument 3: cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'
How to fix this error?
void Main()
{
SortedDictionary<int, string> items = new SortedDictionary<int, string>{{1, "apple"}, {2, "book"}, {3, "tree"}, {4, "mazagine"}, {5, "orange"}};
MultiSelectList msl = new MultiSelectList(items, items.Select(o => o.Key), items.Select(o => o.Value), items.Where(i => i.Key == 1 || i.Key == 5)).Dump();
}
MultiSelectList(items, dataValueField, dataTextField, selectedValues) constructor expects four parameters:
string
- here is your first error. You should pass name of value field instead of passing all values.string
- here is your second error. You should pass name of text field instead of passing all text values.1
and 5
in your case) instead of passing items which have selected values.So, correct code is
new MultiSelectList(items, "Key", "Value", new [] { 1, 5 })
I suggest you to read carefully error messages, look on IntelliSense hints, and use MSDN to get information about types you are using.