你應該使用
@Html.TextBoxFor(model=>model.text1, new {@class="date-picker"});
<script>
$(".date-picker").datepicker();
</script>
OR
1-裏面添加視圖 - > Shared-> EditorTemplates DateTime的新的編輯器
@model System.DateTime?
@if (Model.HasValue)
{
@Html.TextBox("", Model.Value.Date.ToShortDateString(), new { data_datepicker = "true", style="width:80px;" })
}
else
{
@Html.TextBox("", null, new { data_datepicker = "true", style="width:80px;" })
}
<script type='text/javascript'>
$(function() {
$(":input[data-datepicker]").datepicker({
showOtherMonths: true,
selectOtherMonths: true,
showOn: "both",
showAnim: "slide",
showButtonPanel: true,
changeMonth: true,
changeYear: true,
numberOfMonths: 2,
buttonImage: "@Url.Content("~/xtras/images/calendar.png")",
buttonImageOnly: true
});
};
</script>
2-使用編輯器幫助查看
@Html.EditorFor(model=>model.date1)
0123對我而言不適用。 – RollerCosta 2012-02-01 11:45:35