MVC3 @Html.DropDownListFor not populating selected item

前端 未结 1 394
野性不改
野性不改 2020-12-18 13:58

I have the following dropdown list in an MVC3 application and the selected item is not showing a value. My dropdown list is contained in a list of a custom class. My view

相关标签:
1条回答
  • 2020-12-18 14:43

    Try like that:

    @Html.DropDownListFor(
        m => m.PartAttributes[i].Value, 
        new SelectList(
            Model.PartAttributes[i].PartList, 
            "Value", 
            "Text", 
            Model.PartAttributes[i].Value
        ), 
        "Choose Part"
    )
    

    AFAIK the DropDownListFor helper is unable to determine the selected value from the lambda expression that is passed as first argument if this lambda expression represents complex nested properties with collections. Works with simple properties though: m => m.FooBar. I know that it kinda sucks, but hopefully this will be fixed in future versions.

    0 讨论(0)
提交回复
热议问题