问题描述
我有一个MVC5 Web应用程序,我正在尝试让JQuery DatePicker与DateTime EditorTemplates一起使用。
对于我有的编辑器模板;
I have an MVC5 Web application and am trying to get the JQuery DatePicker to work with DateTime EditorTemplates.
For the editor template I have;
@model System.DateTime?
@if (Model.HasValue)
{
@Html.TextBox("", String.Format("{0:ddd MMM dd,yyyy}", Model.Value), new { @class = "datepicker" })
}
else
{
@Html.TextBox("", String.Format("{0:ddd MMM dd,yyyy}", DateTime.Now), new { @class = "datepicker" })
}
Javascript;
the Javascript;
<script>
$(document).ready(function () {
$(".datepicker").datepicker({
dateFormat: 'ddd MMM dd,yyyy',
autoClose: true,
todayBtn: true,
todayHighlight: true
});
});
</script>
,最后是代码;
and finally the code;
<div class="col-lg-2">
<label>Create Date</label><br/>
@Html.EditorFor(model => model.CreateDate, new { @value = @Model.CreateDate" })
</div>
当我点击控件时,会显示DatePicker但是;
1)它不会自动关闭。
2)如果我没有选择日期并点击其他地方,则插入当前日期。
3)首次出现时,日期是我指定的格式; ddd dd MMM,yyyy然后当插入日期时,它永远是MM / dd / yyyy。
我缺少什么?
谢谢你们所有
When I click on the control the DatePicker is displayed but;
1) It doesn't autoclose as it should.
2) If I don't select a date and click off somewhere else the current date is inserted.
3) When it first comes up the date is in the format I specified which is; "ddd dd MMM,yyyy" then when the date is inserted it is "MM/dd/yyyy" forever after.
What am I missing?
Thanks y'all
推荐答案
,最后是代码;
and finally the code;
<div class="col-lg-2">
<label>Create Date</label><br/>
@Html.EditorFor(model => model.CreateDate, new { @value = @Model.CreateDate" })
</div>
当我点击控件时,会显示DatePicker但是;
1)它不会自动关闭。
2)如果我没有选择日期并点击其他地方,则插入当前日期。
3)首次出现时,日期是我指定的格式; ddd dd MMM,yyyy然后当插入日期时,它永远是MM / dd / yyyy。
我缺少什么?
非常感谢
When I click on the control the DatePicker is displayed but;
1) It doesn't autoclose as it should.
2) If I don't select a date and click off somewhere else the current date is inserted.
3) When it first comes up the date is in the format I specified which is; "ddd dd MMM,yyyy" then when the date is inserted it is "MM/dd/yyyy" forever after.
What am I missing?
Thanks y'all
D M dd, yy
格式记录在 []。
似乎也没有提及 autoClose
, todayBtn
或 todayHighlight
选项在 []。
运行 [],我无法重现问题1或2。您不需要任何自定义设置来自动关闭,也不应插入任何未明确选择的日期。
The format is documented under the formatDate
method[^].
There also doesn't appear to be any mention of the autoClose
, todayBtn
or todayHighlight
options in the documentation[^].
Running the demos[^], I can't reproduce problems 1 or 2. You shouldn't need any custom setting to auto-close, and it shouldn't insert any date that you haven't explicitly selected.
这篇关于MVC5 EditorTemplate和Bootstrap DatePicker的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!