仅从TextBoxFor日期() [英] Date only from TextBoxFor()
本文介绍了仅从TextBoxFor日期()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法用TextBoxFor&LT显示日期时间的唯一日期部分到一个文本框;,>(例如pression,htmlAttributes)
该模型是基于LINQ2SQL,现场是SQL和实体模型中的日期时间。
失败:
<%= Html.TextBoxFor(型号=> model.dtArrivalDate,的String.Format({0:DD / MM / YYYY},Model.dtArrivalDate))% >
这招好像是去preciated,在对象htmlAttribute任何字符串值被忽略。
失败:
[DisplayFormat(DataFormatString ={0:DD / MM / YYYY})]
公共字符串dtArrivalDate {搞定;组; }
我要存储和显示仅在细节/编辑视图日期部分,没有00:00:00开始的部分。
解决方案
[DisplayName的(开始日期)]
[DisplayFormat(ApplyFormatInEditMode = TRUE,DataFormatString ={0:YYYY-MM-DD})]
公开日期时间起始日期{搞定;组; }
然后:
<%= Html.EditorFor(M = GT; m.StartDate)%GT;
I'm having trouble displaying the only date part of a DateTime into a textbox using TextBoxFor<,>(expression, htmlAttributes).
The model is based on Linq2SQL, field is a DateTime on SQL and in the Entity model.
Failed:
<%= Html.TextBoxFor(model => model.dtArrivalDate, String.Format("{0:dd/MM/yyyy}", Model.dtArrivalDate))%>
This trick seems to be depreciated, any string value in the object htmlAttribute is ignored.
Failed:
[DisplayFormat( DataFormatString = "{0:dd/MM/yyyy}" )]
public string dtArrivalDate { get; set; }
I would like to store and display only the date part on the details/edit view, without the "00:00:00" part.
解决方案
[DisplayName("Start Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime StartDate { get; set; }
Then:
<%=Html.EditorFor(m => m.StartDate) %>
这篇关于仅从TextBoxFor日期()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文