创建后 MVC 日历值未保存到数据库
MVC Calendar values not saved to database after creating
创建视图
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<br />
<label>Start Time</label>
<br />
<div class="dp">
<input type="text" class="form-control" id="datetimepicker6" />
</div>
</div>
</div>
Javascript 日历
<script type="text/javascript">
var array = ["2015-12-25", "2015-12-24", "2015-12-31"]
$('.datepicker').datepicker({
beforeShowDay: function (date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return [array.indexOf(jQuery.datepicker.formatDate('yy-mm-dd', date)) == -1]
} else {
return noWeekend;
}
}, minDate: 0
});
$(function () { $('#startDate').datepicker({ beforeShowDay: $.datepicker.noWeekends }); });
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datetimepicker6').datetimepicker({
minDate: new Date(currentYear, currentMonth, currentDate), daysOfWeekDisabled: [0, 6],
disabledDates: [
moment("12/25/2015"),
moment("12/24/2015")
]
});
$('#datetimepicker7').datetimepicker({
minDate: new Date(currentYear, currentMonth, currentDate), daysOfWeekDisabled: [0, 6],
disabledDates: [
moment("12/25/2015"),
moment("12/24/2015")
]
});
});
</script>
我有一个创建操作,我可以在其中使用日历选择开始日期和结束日期。但是在我 select 日期并创建之后,日期不会保存在数据库中,但相同形式的其他值会保存。因此它也不会出现在 table 中。我该如何解决?
您手动生成了 <input>
元素,但没有给它一个 name
属性,所以它的值不会回发。 name
属性需要与您的模型名称 属性 匹配,生成此属性的最佳方法是使用强类型 html 帮助程序
@Html.TextBoxFor(m => m.yourPropertyName, new { @class = "form-control" })
这将生成一个 id
属性 id="yourPropertyName"
以便脚本可以引用 $('#yourPropertyName').datetimepicker()
。或者,您可以使用 new { @class = "form-control", id="datetimepicker6" }
给它一个不同的 id
属性
创建视图
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<br />
<label>Start Time</label>
<br />
<div class="dp">
<input type="text" class="form-control" id="datetimepicker6" />
</div>
</div>
</div>
Javascript 日历
<script type="text/javascript">
var array = ["2015-12-25", "2015-12-24", "2015-12-31"]
$('.datepicker').datepicker({
beforeShowDay: function (date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return [array.indexOf(jQuery.datepicker.formatDate('yy-mm-dd', date)) == -1]
} else {
return noWeekend;
}
}, minDate: 0
});
$(function () { $('#startDate').datepicker({ beforeShowDay: $.datepicker.noWeekends }); });
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datetimepicker6').datetimepicker({
minDate: new Date(currentYear, currentMonth, currentDate), daysOfWeekDisabled: [0, 6],
disabledDates: [
moment("12/25/2015"),
moment("12/24/2015")
]
});
$('#datetimepicker7').datetimepicker({
minDate: new Date(currentYear, currentMonth, currentDate), daysOfWeekDisabled: [0, 6],
disabledDates: [
moment("12/25/2015"),
moment("12/24/2015")
]
});
});
</script>
我有一个创建操作,我可以在其中使用日历选择开始日期和结束日期。但是在我 select 日期并创建之后,日期不会保存在数据库中,但相同形式的其他值会保存。因此它也不会出现在 table 中。我该如何解决?
您手动生成了 <input>
元素,但没有给它一个 name
属性,所以它的值不会回发。 name
属性需要与您的模型名称 属性 匹配,生成此属性的最佳方法是使用强类型 html 帮助程序
@Html.TextBoxFor(m => m.yourPropertyName, new { @class = "form-control" })
这将生成一个 id
属性 id="yourPropertyName"
以便脚本可以引用 $('#yourPropertyName').datetimepicker()
。或者,您可以使用 new { @class = "form-control", id="datetimepicker6" }
id
属性