jquery datepicker+Html.TextBoxFor
我有一个关于jquerydatepicker和TextBoxFor方法的问题。 我有一个asp.net表单,在其中我使用它们来创建和编辑对象。我使用相同的表单进行编辑和创建。 看起来是这样的:jquery datepicker+Html.TextBoxFor,jquery,datepicker,Jquery,Datepicker,我有一个关于jquerydatepicker和TextBoxFor方法的问题。 我有一个asp.net表单,在其中我使用它们来创建和编辑对象。我使用相同的表单进行编辑和创建。 看起来是这样的: <script> $(function () { $("#datepicker2").datepicker( { dateFormat: 'yy.mm.dd' }); }); </s
<script>
$(function () {
$("#datepicker2").datepicker(
{
dateFormat: 'yy.mm.dd'
});
});
</script>
<div class=demo><%= Html.TextBoxFor(m => m.Distribution.ToDate, new { id = "datepicker2", type = "text" })%></div>
它工作得很好,但我的问题是,当我使用“编辑”时,如何格式化日期?对于create,它是可以的,因为它将显示一个空文本框,如果我选择了一个日期,它将是正确的格式。在“编辑”中,它首先显示整个日期时间值,如果我选择了一个日期,它将以我想要的方式显示该日期。但是我该怎么做,这样从一开始它就会以我想要的方式显示它
我试着这样做:
<%= Html.TextBoxFor(m => m.Distribution.ToDate.ToShortDateString(), new { id = "datepicker2", type = "text" })%>
但它给出了一个错误
有什么建议吗
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#startDatePicker').datepicker({ clickInput: true });
});
</script>
<% var attributes = (new Dictionary<string, object> { { "Value", Model.Plan.StartDate.ToShortStrin() } }); %>
<% attributes.Add("style", "width:80px; text-align:right"); %>
<% attributes.Add("ID", "startDatePicker"); %>
<%: Html.TextBoxFor(model => model.Plan.StartDate, attributes)%>