开发者

MVC2 Model Binding - Why do I always get back 01/01/0001 in my DateTime Field?

开发者 https://www.devze.com 2023-01-25 09:34 出处:网络
I have a ThingViewModel with a DateTime property: public class ThingViewModel { public D开发者_运维问答ateTime ConfigDate{get;set;}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消