Search code examples
c#asp.net-mvcrazorhtml-helperdropdownlistfor

MVC DropDownListFor Bind on Nested Class


Sorry this is probably really obvious but I just need to check. I have a class with nested classes within containing related information. The Class is singular and not in a list or anything yet MVC wont bind to the field.

Model

public class Car
{
    public GloveBoxDetail GloveBox = new GloveBoxDetail();
}

public class GloveBoxDetail
{
    public bool isLockable{get;set;}
}

View

@Html.DropDownListFor(model => model.GloveBox.isLockable, new SelectList(...))

Am I going to have to manually create the DropDownList's?

Thanks

Chris


Solution

  • managed to figure it out last night. Its only for displaying data so updating the model isn't required so I don't need to worry about binding on a post back. I solved it by setting the "Selected Value" of the Select List to the model, dirty but it works.

    Thanks

    Chris