C# 第页上日期时间的时间格式
我有一处房产C# 第页上日期时间的时间格式,c#,asp.net-mvc,datetime,time,C#,Asp.net Mvc,Datetime,Time,我有一处房产 [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mmtt}")] public DateTime DeadlineTime { get; set; } 在第页使用它 <div class="form-group"> @Html.LabelFor(model => model.DeadlineTime, htmlAttributes
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mmtt}")]
public DateTime DeadlineTime { get; set; }
在第页使用它
<div class="form-group">
@Html.LabelFor(model => model.DeadlineTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DeadlineTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DeadlineTime, "", new { @class = "text-danger" })
</div>
</div>
@LabelFor(model=>model.DeadlineTime,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.DeadlineTime,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.DeadlineTime,“,new{@class=“text danger”})
但当我尝试输入如下值:11:30PM时,我得到一个验证程序错误:
字段DeadlineTime必须是日期
为什么以及如何解决它?为什么不使用
TimeSpan
?research@dlatikay我的问题是时间,而不是日期。所以,datepicker与我的问题无关,我明白。不过,我在那篇文章中提到的第四个答案暗示了一个可能适用于您的情况的问题:输入控件在客户端呈现为
吗?11:30PM
无法解析为DateTime
typeof(它没有年、月或日组件。您的属性需要是TimeSpan
,或者您需要自定义ModelBinder
将值转换为DateTime