【发布时间】:2010-03-23 03:33:33
【问题描述】:
我正在尝试使用 Html.DropDownListFor HtmlHelper,但在绑定帖子时遇到了一些麻烦。 HTML 可以正确呈现,但我在提交时从未获得“选定”值。
<%= 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
} );
}
}
我尝试了一些不同的东西,但我确信我在做一些愚蠢的事情......只是不确定它是什么:)
【问题讨论】:
标签: asp.net-mvc viewmodel