format htmlhelper date field to dd/mm/yyyyy
I need to encode an htmlhelper date to "{0:dd/mm/yyyy}. Current result in dd/mm/yyyy hr:mins:sec
<%= Html.Encode(Model.myTable.DOB)%>
I also need to enforce a datepicker to format "dd/mm/yyyy".
<%= Html.DatePicker("DOB", "/Content/Images/calendar.png", Model.App开发者_高级运维licantStatus.DOB)%>
to mask date on Html.Encode, use:
<%= String.Format("{0:dd/MM/yyyy}", Model.myTable.DOB%>
to format dd/mm/yyyy, use:
<input type="image" src="/Content/Images/calendar.png" id="DOB" name="DOB" value='<%=String.Format("{0:dd/MM/yyyy}", Model.myTable.DOB)%>'/>
You can go to the datepicker class, and set up default value to the correct
dateFormat: 'dd/mm/yy'
and value you format as:
Model.myTable.DOB.ToString("dd/MM/yyyy")
and if you provide new value for the element use following
<%: Html.Helper("yourfield", new {ID="datepicker", @Value="your newValue"}) %>
good luck
精彩评论