2023-02-17 387
我遇到了使用TextBoxfor (表达式,HTMLAttributes)的TextBox中唯一的日期时间的日期部分.
模型基于Linq2SQL,字段是SQL和实体模型中的DATETIME.
失败:
<%= Html.TextBoxFor(model => model.dtArrivalDate, String.Format("{0:dd/MM/yyyy}", Model.dtArrivalDate))%>
此技巧似乎折旧,忽略了对象htmlattribute中的任何字符串值.
失败:
[DisplayFormat( DataFormatString = "{0:dd/MM/yyyy}" )]
public string dtArrivalDate { get; set; }
我想在没有”00:00:00″部分的情况下,仅在详细信息/编辑视图上存储并显示日期部分.
[DisplayName("Start Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime StartDate { get; set; }
然后:
<%=Html.EditorFor(m => m.StartDate) %>
mvc4 通过添加新的TextBoxFor过载来解决了此问题,它采用字符串格式参数.您现在可以简单地执行以下操作:
@Html.TextBoxFor(m => m.EndDate, "{0:d MMM yyyy}")
还有一个reledlo占HTML属性,因此您可以设置CSS类,电汇DatePickers等:
@Html.TextBoxFor(m => m.EndDate, "{0:d MMM yyyy}", new { @class="input-large" })
<%= Html.TextBoxFor(model => model.EndDate, new { @class= "jquery_datepicker", @Value = Model.EndDate.ToString("dd.MM.yyyy") })%>
以上所述是小编给大家介绍的仅来自TextBoxFor()的日期,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!
原文链接:https://77isp.com/post/34227.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态