I have a drop down list that isn't working correctly. I can get the correct items from the db and display them on the get, but when I post back on submit 'listLanguages' is null. I'm not sure if my html DropDownListFor properties are correct?
Here is my code
in my viewmodel
public IEnumerable<SelectListItem> listLanguages { get; set; }
in my View
@Html.DropDownListFor(model => model.ProfileGeneralViewModel.listLanguages, Model.ProfileGeneralViewModel.listLanguages, new { @class = "multiple-languages form-control", @style = "width: 100%", @multiple = "multiple" })
here's my get
var languages = Enum.GetNames(typeof(SpokenLanguages)).AsEnumerable();
var selectedLanguages = yogaProfile.Languages != null ? yogaProfile.Languages.Split(',').ToList() : new List<string>();
viewModel.ProfileGeneralViewModel.listLanguages = languages.Select(d => new SelectListItem
{
Text = d.ToString(),
Value = d.ToString(),
Selected = selectedLanguages.Contains(d.ToString())
});