ASP.Net MVC DisplayFormat [英] ASP.Net MVC DisplayFormat
本文介绍了ASP.Net MVC DisplayFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的模型我有我的属性之一以下DataAnnotations
In my model I have the following DataAnnotations on one of my properties
[Required(ErrorMessage = "*")]
[DisplayFormat(DataFormatString = "{0:d}")]
[DataType(DataType.Date)]
public DateTime Birthdate { get; set; }
所要求标注的伟大工程,我添加了其他2个尝试和删除的时间。它被使用绑定到一个输入视图
The required annotation works great, I added the other 2 to try and remove the time. It gets bound to an input in the view using
<%=Html.TextBoxFor(m => m.Birthdate, new { @class = "middle-input" })%>
然而,每当视图加载我仍然得到出现在输入框中输入时间。反正是有使用DataAnnotations删除此?
However whenever the view loads I still get the time appearing in the input box. Is there anyway to remove this using DataAnnotations?
推荐答案
在[DisplayFormat]属性只在EditorFor / DisplayFor,而不是由原始的HTML API,如TextBoxFor使用。
The [DisplayFormat] attribute is only used in EditorFor/DisplayFor, and not by the raw HTML APIs like TextBoxFor.
这篇关于ASP.Net MVC DisplayFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文