我有一个关于jquerydatepicker和TextBoxFor()方法的问题。我有一个asp.net表单,我在其中使用它们来创建和编辑对象。我使用相同的表单进行编辑和创建。它看起来是这样的:
<script>
$(function () {
$("#datepicker2").datepicker(
{
dateFormat: 'yy.mm.dd'
});
});
</script>
<div class=demo><%= Html.TextBoxFor(m => m.Distribution.ToDate, new { id = "datepicker2", type = "text" })%></div>它工作得很好,但我的问题是,当我使用edit时,我如何格式化日期?对于create是可以的,因为它将显示一个空的文本框,如果我选择一个日期,它将是正确的格式。在编辑中,它首先显示整个日期时间值,如果我选择一个日期,它会按照我想要的方式显示那个日期。但是我该怎么做,才能让它一开始就以我想要的方式显示它呢?
我试着这样做:
<%= Html.TextBoxFor(m => m.Distribution.ToDate.ToShortDateString(), new { id = "datepicker2", type = "text" })%>但它会给出一个错误。
有什么建议吗?
发布于 2011-02-19 02:29:01
<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)%>https://stackoverflow.com/questions/4489422
复制相似问题