【问题标题】:MVC2 Model Binding - Why do I always get back 01/01/0001 in my DateTime Field?MVC2 模型绑定 - 为什么我总是在我的 DateTime 字段中返回 01/01/0001?
【发布时间】:2010-11-17 22:15:41
【问题描述】:

我有一个带有 DateTime 属性的 ThingViewModel:

public class ThingViewModel
{    
  public DateTime ConfigDate{get;set;}
}

我的视图引用了它导入和呈现的 ViewUserControl,并带有 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 ) %>
<% } %>

我的索引操作已将 ConfigDate 的值设置为今天:

public ActionResult Index()
{
ThingsViewMode tvm = new ThingsViewModel
{
   ConfigDate = DateTime.Now.Date
};
 return View(tvm);
 }

一切正常。但是,在我返回 POST 表单时的 Details 方法中,我为 ConfigDate 返回的只是 "01/01/0001 12:00:00 AM" 的 DateTime 值。

我做错了什么?

【问题讨论】:

  • 回帖是否显示 01/01/0001 等?或服务器回复后
  • 发布您的[HttpPost] 方法。你是怎么绑定的?

标签: asp.net-mvc-2 forms viewmodel model-binding


【解决方案1】:

我在重定向中失去了价值。过错。

【讨论】:

    猜你喜欢
    • 2013-05-17
    • 2013-07-23
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多