编辑时可以允许datetime num吗?

时间:2012-10-05 02:34:43

标签: asp.net-mvc asp.net-mvc-4

我遇到了一个问题。 那就是我在模型中用entity定义datetime属性并允许null。 喜欢这个

class T_NAME 
[key] int key 
 Datetime F_DATE  
 string F_NAME 

我使用此模型的默认视图来创建。 我打算首先添加此记录并稍后修改日期,但它显示该字段是必需的(我允许null @database)。

我该怎么做? THX。

1 个答案:

答案 0 :(得分:0)

将您的媒体资源更改为nullable

public class T_Name
{
  [Key]
  public int Key { set;get;}
  public DateTime? F_Date { set;get;}
  public string F_Name { set;get;}
}