我正在使用datetimepicker,我想禁用控制器中的特定日期及其之前的所有日期。禁用特定的日期及其之前的所有日期
那麼如何將日期從控制器傳遞給datetimepicker?
這裏是我的意思是:
MRecord firstMR = db.MRecords.Where(x => x.AID == dSum.AircraftID).OrderBy(x => x.DateEntered).FirstOrDefault();
<script type="text/javascript">
$(function() {
$('#datetimepicker5').datetimepicker({
disabledDates: [
// how do I disable all dates before and including firstMR.DateEntered?
]
});
});
</script>
是否有可能做這一切的看法?我正在使用剃鬚刀。
任何幫助表示讚賞。
UPDATE
我在Razor視圖嘗試這樣的:
@{
ViewBag.Title = "Create";
var firstMR = new ALogSummary.Models.MRecord();
using (var db = new AviationLogSummary.Models.ALogsEntities())
{
firstMR = db.MRecords.Where(x => x.AID == Model.AID).OrderBy(x => x.DateEntered).FirstOrDefault();
}
}
<div id="datetimepicker2" class="input-group date">
@Html.EditorFor(model => model.Day, new { htmlAttributes = new { id = "Day", @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Day, "", new { @class = "text-danger" })
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
$(function() {
$('#datetimepicker2').datetimepicker({
format: 'MM/DD/YYYY HH:mm',
minDate: [@firstMR.DateEntered.Date]
});
});
</script>
當我調試,我收到此錯誤:
JavaScript的嚴重錯誤的行160,列49 in http://localhost:xxxxx/DSummaries/Create/7 \ n \ nSCRIPT1007:Expected']'
更新2:
<div id="datetimepicker2" class="input-group date" >
@Html.EditorFor(model => model.Day, new { htmlAttributes = new { id = "Day", @class = "form-control", data_mindate = firstMR.DateEntered.Date } })
@Html.ValidationMessageFor(model => model.Day, "", new { @class = "text-danger" })
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
SCRIPT:
這是它自己的JS文件
$(function() {
$('#datetimepicker2').datetimepicker({
format: 'MM/DD/YYYY HH:mm',
minDate: $(this).data('mindate')
});
});
的HTML輸出是:
<input class="form-control text-box single-line valid" id="Day" type="datetime" data-val-required="This field is required!" data-val="true" data-mindate="05/28/2016 00:00:00" data-val-date="This field: must be a date." value="06/28/2016 09:07"></input>
所以正確的思想被填充,但我的腳本不工作。
爲什麼不直接使用'minDate'選項(並將其設置爲'firstMR.DateEntered'的價值)? –
@StephenMuecke我更新了我的問題。這是你的建議嗎? –
刪除方括號('minDate'是一個值,而不是值的數組。 –