Asp.net mvc 4 将值分配给格式为MM/YYYY的引导datetimepicker会显示不正确的年份
我正在ASP MVC 4应用程序中使用版本4.17.47 我有这个模型属性:Asp.net mvc 4 将值分配给格式为MM/YYYY的引导datetimepicker会显示不正确的年份,asp.net-mvc-4,bootstrap-datetimepicker,eonasdan-datetimepicker,Asp.net Mvc 4,Bootstrap Datetimepicker,Eonasdan Datetimepicker,我正在ASP MVC 4应用程序中使用版本4.17.47 我有这个模型属性: public DateTime MonthYear { get; set; } 我在控制器中分配默认值(任意值只是一个示例,实际值是通过一些逻辑确定的): 我使用datepicker在视图中显示该值,以便用户可以根据需要更新该值: @Html.TextBoxFor(model => model.MonthYear, new { @class = "form-control input month-picker"
public DateTime MonthYear { get; set; }
我在控制器中分配默认值(任意值只是一个示例,实际值是通过一些逻辑确定的):
我使用datepicker在视图中显示该值,以便用户可以根据需要更新该值:
@Html.TextBoxFor(model => model.MonthYear, new { @class = "form-control input month-picker" })
脚本:
$('.month-picker').datetimepicker({
format: 'MM/YYYY',
useCurrent: false,
toolbarPlacement: 'bottom',
viewMode: 'months'
});
问题在于控件显示“03/0001”而不是“03/2017”
我在这里遗漏了什么?显然,问题在于,当datetimepicker只期望MM/YYYY时,输入被来自服务器的DD/MM/YYYY日期填充。尝试格式化文本框,如:
@Html.TextBoxFor(model => model.MonthYear, "{0:MM/yyyy}", new { @class = "form-control input month-picker" })
那应该行。好的。。看起来真的没问题。。您是否尝试删除datetimepicker只是为了查看文本框中是否填充了预期的数据?@drigomed当我删除picker时,我得到了“2017年3月1日12:00:00 AM”
@Html.TextBoxFor(model => model.MonthYear, "{0:MM/yyyy}", new { @class = "form-control input month-picker" })