I have a ThingViewModel with a DateTime property:
public class ThingViewModel
{
public D开发者_运维问答ateTime ConfigDate{get;set;}
}
My view has a reference to a ViewUserControl that it imports and renders, with the textbox for ConfigDate:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ThingViewModel>
<% using (Html.BeginForm("Details",
"Things",
FormMethod.Post,
new { id = "SearchForm"})) {% >
<%= Html.TextBoxFor( Model => Model.ConfigDate ) %>
<% } %>
My Index Action has sets the value of the ConfigDate to today:
public ActionResult Index()
{
ThingsViewMode tvm = new ThingsViewModel
{
ConfigDate = DateTime.Now.Date
};
return View(tvm);
}
which is all working just fine. However, in the Details method when I get the form POST back, all I EVER get back for ConfigDate is the DateTime value of "01/01/0001 12:00:00 AM"
.
What am I doing wrong?
I was losing the value in a redirect. Mea Culpa.
精彩评论