I'm trying to implement an MVC webpage, that contains a dropdown for enums.
It works fine, when bound to a single-valued property, like MyEnum MyProperty {get;set;}
Now, I'd like to turn it into a multiselect list - but in this case @Html.EnumDropDownListFor()
fails with the following exception:
Return type 'System.Collections.Generic.List'1[[MyNamespace, Version=1.0.0.0, Culture=neutral, MyEnum=null]]' is not supported. Parameter name: expression'
A similar thing for string collections works fine. Any ideas?
Model
public IEnumerable StringValues;
[Display(Name = "Works fine for strings")]
public IEnumerable<string> StringCollectionProperty { get; set; }
[Display(Name = "Fails for enums")]
[EnumDataType(typeof(MyEnum))]
public IEnumerable<ProcessingStatus> MyEnumCollectionProperty { get; set; }
View
// This works fine
@Html.DropDownListFor(model => model.StringCollectionProperty, Model.StringValues, htmlAttributes: new { @class = "form-control", multiple = "multiple" })
// This fails with the error above
@Html.EnumDropDownListFor(model => model.MyEnumCollectionProperty, "Please select...", htmlAttributes: new { @class = "form-control", multiple = "multiple" })