C# MVC EF-日期时间格式
这是我的班级:C# MVC EF-日期时间格式,c#,asp.net-mvc,entity-framework,datetimepicker,C#,Asp.net Mvc,Entity Framework,Datetimepicker,这是我的班级: public partial class Post { public Post() { this.PostImages = new HashSet<PostImage>(); this.PostMappings = new HashSet<PostMapping>(); } public int ID { get; set; } public string Title { get;
public partial class Post
{
public Post()
{
this.PostImages = new HashSet<PostImage>();
this.PostMappings = new HashSet<PostMapping>();
}
public int ID { get; set; }
public string Title { get; set; }
public string TitleMenu { get; set; }
public string Preview { get; set; }
public string Content { get; set; }
public Nullable<int> Display { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> DateAdded { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> DateHide { get; set; }
public Nullable<int> PozitionMenu { get; set; }
public string Username { get; set; }
public virtual ICollection<PostImage> PostImages { get; set; }
public virtual ICollection<PostMapping> PostMappings { get; set; }
}
我在web.config中添加了:
<globalization culture="en-US" />
我仍然得到了错误:
值“20/02/2014”对DateHide无效。替换
$('.jquery_datepicker').datepicker({ dateFormat: "dd/mm/yy" });
借
这将以“02/20/2014”的格式将日期传递给模型。I
@Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})
与
与
现在它工作了!但我不知道为什么。EditorFor和TextboxFor之间有什么区别
dd/mm/yy
不是美国日期格式。确定。我从web.config中删除了全球化,但仍然得到相同的错误。堆栈跟踪是什么?在哪里得到错误的?当我尝试更新Post元素时。
$('.jquery_datepicker').datepicker({ dateFormat: "mm/dd/yy" });
@Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})
<span class="jquery_datepicker"> @Html.EditorFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value =Model.DateHide, displayMode })</span>
$('.jquery_datepicker').datepicker({ dateFormat: "dd/mm/yy" });
$('.jquery_datepicker input').datepicker({ dateFormat: "dd/mm/yy" });