MVC2 Binding isn't working for Html.DropDownListFor<>
Posted
by devlife
on Stack Overflow
See other posts from Stack Overflow
or by devlife
Published on 2010-03-23T03:33:33Z
Indexed on
2010/03/23
3:41 UTC
Read the original article
Hit count: 759
asp.net-mvc
|viewmodel
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 :)
© Stack Overflow or respective owner