I'm trying to use the Html.DropDownListFor<> HtmlHelper and am having a little trouble binding on post. The HTML renders properly but I never get a "selected" value when submitting.
<%= Html.DropDownListFor( m => m.TimeZones,
Model.TimeZones,
new { @class = "SecureDropDown",
name = "SelectedTimeZone" } ) %>
[Bind(Exclude = "TimeZones")]
public class SettingsViewModel : ProfileBaseModel
{
public IEnumerable TimeZones { get; set; }
public string TimeZone { get; set; }
public SettingsViewModel()
{
TimeZones = GetTimeZones();
TimeZone = string.Empty;
}
private static IEnumerable GetTimeZones()
{
var timeZones = TimeZoneInfo.GetSystemTimeZones().ToList();
return timeZones.Select(t => new SelectListItem
{
Text = t.DisplayName,
Value = t.Id
} );
}
}
I've tried a few different things and am sure I am doing something stupid... just not sure what it is :)