In my C#, MVC4 .NET WebApplication I have a custom helper that has the following method-call:
@Custom.DropDownListFor(m => m.CategorySetups[categoryId].Gender, CategoryHelper.Genders, new { @class = "form-control" })
which is internally something like:
@Html.DropDownListFor(expression, new SelectList(items, "Value", "Text"))
because I have an override of SelectListItem here.
This call is not selecting the value in the rendered view as stored in
m.CategorySetups[categoryId].Gender
If I call the method this way (not in the same view):
@Custom.DropDownListFor(m => m.Gender, CategoryHelper.Genders, new { @class = "form-control" })
The rendered HTML has the correct value marked as
<option value="Under15" selected>Under15</option>
So my guess is, that is has something to do with nesting of the property that is selected but I don't see it.
From debugging I can see, that
m.CategorySetups[categoryId].Gender
has the correct value set when it should render the select.
Note: Not sure if this may causing the issue (because the second way it's working) but the bound values Type is Enum.
Update as of comments:
The implementation is as follows:
public static readonly List<SelectListItem<ClassificationType>> ClassificationTypes = new List<SelectListItem<ClassificationType>>
{
new SelectListItem<ClassificationType> {Text = @"please select...", Value = ClassificationType.NotSet},
new SelectListItem<ClassificationType> {Text = EnumParser.GetString(ClassificationType.Under13), Value = ClassificationType.Under13},
new SelectListItem<ClassificationType> {Text = EnumParser.GetString(ClassificationType.Under15), Value = ClassificationType.Under15},
new SelectListItem<ClassificationType> {Text = EnumParser.GetString(ClassificationType.Under18), Value = ClassificationType.Under18},
new SelectListItem<ClassificationType> {Text = EnumParser.GetString(ClassificationType.Over30), Value = ClassificationType.Over30},
new SelectListItem<ClassificationType> {Text = EnumParser.GetString(ClassificationType.Open), Value = ClassificationType.Open}
};