I have a search box on my page that needs to be populated with the previous search terms; i.e. if a person searches for "First name: John" the firstname box shows up with "John" already entered in.

I have several dropdown lists, and all of them work except for the "family member" dropdowns. For example, this works:

    @Html.DropDownListFor(m => m.Database, new SelectList(@Model.DatabaseDropdown))

I get a dropdown with my list of all available databases (which is in the viewmodel), and if a database was included in the search, that database is already selected. However, I have 3 more dropdowns (one for each family member search field), for selecting family members type ("Father", "Mother", or "Spouse", or a default label of "Family Member").

    @Html.DropDownListFor(m => m.FamilyMembers[0].Relationship, new SelectList(@Model.FamilyTypes))

It's the exact same format, and I know that FamilyMembers[0].Relationship has a value, because when I add this:

    @Html.DropDownListFor(m => m.FamilyMembers[0].Relationship, new SelectList(@Model.FamilyTypes))

and select "Father" from the dropdown and do a search, the page will say "Father" above the select box, but the select box itself will have the default value of "Family Members."

I also tried this:

    @Html.DropDownListFor(m => m.FamilyMembers[0].Relationship, new SelectList(new List<string>() { "Family Member", "Father", "Mother", "Spouse" }))

where I put in the select list manually, but with both versions the select list always shows up with no value selected (that is, showing "Family Members"), even though FamilyMembers[0].Relationship is a valid value in the list.

Related posts

Recent Viewed