When using EnumDropDownListFor on a nested property on a model, the dropdown values are populated but the current selection is not selected.
Functional impact
EnumDropDownListFor is only ever useful for top level model properties.
Minimal repro steps
public class Model
{
public MyEnumType MyEnum { get; set; }
public FooModel Foo { get; set; }
}
public class FooModel
{
public MyEnumType MyEnum { get; set; }
}
public enum MyEnumType
{
A,
B,
C
}
…
model.MyEnum = MyEnumType.B;
model.Foo.MyEnum = MyEnumType.B;
@model Model
@* Works fine, B is selected *@
@Html.EnumDropDownListFor(m => m.MyEnum)
@* Does not work, B is not selected *@
@Html.EnumDropDownListFor(m => m.Foo.MyEnum)
Expected result
The value of B is selected in the dropdown in the second case above.
Actual result
The select options render with none of them being selected.
Title
When using EnumDropDownListFor on a nested property on a model, the dropdown values are populated but the current selection is not selected.
Functional impact
EnumDropDownListFor is only ever useful for top level model properties.
Minimal repro steps
Expected result
The value of B is selected in the dropdown in the second case above.
Actual result
The select options render with none of them being selected.
Further technical details
Using MVC 5.27 from NuGet