值未使用三个 DropDownList 从编辑器模板部分页面视图更新
我在 DateTime 的 PartialPageView 中有一个 EditorTemplate,它具有三个分别表示日、月和年的 DropDownList。当我尝试更新值时,回发日期始终为 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 }))%>
I have a EditorTemplate in a PartialPageView for a DateTime which has three DropDownLists for the day, month, and year. When I try to update the values the postback Date is always 01/01/0001. Any ideas?
<%@ 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 }))%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要处理这种情况,您可能需要 编写自定义模型绑定器。
To handle this case you might need to write a custom model binder.