不使用三个DropDownLists从编辑器Tempale部分页面视图更新值

时间:2010-11-23 23:15:52

标签: asp.net-mvc partial-views editortemplates

我在PartialPageView中有一个EditorTemplate用于DateTime,它有三个用于日,月和年的DropDownLists。当我尝试更新值时,回发日期始终为01/01/0001。有什么想法吗?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%= Html.DropDownListFor(x => x.Value.Day, Enumerable.Range(1, 31).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString(), Selected = i == Model.Value.Day ? true: false})) %>
<%= Html.DropDownListFor(x => x.Value.Month, Enumerable.Range(1, 12).Select(i => new SelectListItem { Value = i.ToString(), Text = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i), Selected = i == Model.Value.Month ? true : false }))%>
<%= Html.DropDownListFor(x => x.Value.Year, Enumerable.Range(1900, 110).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString(), Selected = i == Model.Value.Year ? true : false }))%>

1 个答案:

答案 0 :(得分:0)

要处理此案例,您可能需要write a custom model binder