如何使用Html.TextBoxForwithinputtype=date?我想在我的代码中实现。为此,我有以下内容:@Html.TextBoxFor(model=>model.CreationDate,new{@type="date"})此代码生成以下HTML:该值未显示在网页上,因为type="date"需要YYYY-MM-DD格式的数据。我试过格式化日期,但它当然会爆炸。@Html.TextBoxFor(model=>model.CreationDate.ToString("YYYY-MM-DD"),new{@type="date"})如何使用TextBoxFor方法正确显示构造?或者我应该使用其他东西(我试过EditorFor但失败了)?CreationDate是DateTime类型。尝试这个;@Html.TextBoxFor(model=>model.CreationDate,new{@type="date",@Value=Model.CreationDate.ToString("yyyy-MM-dd")})设置值时必须处理空值。或者如果你可以改变模型,你可以试试这个;[DataType(DataType.Date)][DisplayFormat(DataFormatString="{0:yyyy-MM-dd}",ApplyFormatInEditMode=true)]publicDateTimeCreationDate{get;放;在您看来,您可以使用EditorFor助手。@Html.EditorFor(model=>model.CreationDate,new{@type="date"})模型设计:[DataType(DataType.Date)][DisplayFormat(DataFormatString="{0:yyyy-MM-dd}",ApplyFormatInEditMode=true)]publicDateTimeCreationDate{get;放;}查看设计:m.CreationDate,new{@type="date"})%>我对EditorFor和boostrap-datepicker库做了类似的事情:@Html。EditorFor(m=>m.StartDate)Convertc#DatetimetoHTML-5Datevalue以上为C#学习教程:HowtouseHtml.TextBoxForwithinputtype=date?分享的所有内容,如果对你有用,需要了解更多C#学习教程,希望大家多加关注——》/>本文整理自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,如有请注明出处:
