aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

EnumDropDownListFor does not select the current value when the field is nested #269

Closed abidingotter closed 4 years ago

abidingotter commented 4 years ago

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

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.

Further technical details

Using MVC 5.27 from NuGet

mkArtakMSFT commented 4 years ago

Thank you for contacting us. We are currently only fixing critical functional issues in the code base, and have decided to not make this change.