El valor no actualizar desde un editor tempale parcial Ver página utilizando tres DropDownLists

StackOverflow https://stackoverflow.com/questions/4262012

Pregunta

Tengo un EditorTemplate en un PartialPageView para un DateTime que tiene tres DropDownLists para el día, mes y año. Cuando intento actualizar los valores de la fecha de devolución de datos es siempre 01/01/0001. Algunas 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 }))%>
¿Fue útil?

Solución

Para manejar este caso es posible que necesite escribir un modelo personalizado ligante .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top