在剃刀形式中使用日期选择器 - ASP.NET MVC
Using Datepicker In Razor Form - ASP.NET MVC
我有一个我喜欢并且可以使用的日期选择器。 It displays as a neat box in line with the rest of my form and clicking the box prompts a datepicker component, where when a date is selected, a text box is populated.
标记:
<div class="form-group">
<div id="datepicker-group" class="input-group date" data-date-format="dd/mm/yyyy">
<input class="form-control" name="data" type="text" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
JQuery
<script>
$(document).ready(function() {
$("#datepicker-group").datepicker({
format: "dd-M-yyyy",
todayHighlight: true,
autoclose: true,
clearBtn: true
});
});
</script>
我还有一个正在使用 @Html.BeginForm
构建的表单,我模型中的其他属性通过 @Html.TextBoxFor
和自由文本字段分配它们的值,这很简单。我如何将这个日期选择器 div 放入可以分配给我的 StartDate
属性 的表单域中?除了能够单击该框并弹出日期选择器组件的功能外,我还想保留当前日期选择器框的外观。
你能不能不这样做
<div class="form-group">
<div id="datepicker-group" class="input-group date" data-date-format="dd/mm/yyyy">
@Html.TextBoxFor(x => x.StartDate, new {@class="form-control" })
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
我有一个我喜欢并且可以使用的日期选择器。 It displays as a neat box in line with the rest of my form and clicking the box prompts a datepicker component, where when a date is selected, a text box is populated.
标记:
<div class="form-group">
<div id="datepicker-group" class="input-group date" data-date-format="dd/mm/yyyy">
<input class="form-control" name="data" type="text" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
JQuery
<script>
$(document).ready(function() {
$("#datepicker-group").datepicker({
format: "dd-M-yyyy",
todayHighlight: true,
autoclose: true,
clearBtn: true
});
});
</script>
我还有一个正在使用 @Html.BeginForm
构建的表单,我模型中的其他属性通过 @Html.TextBoxFor
和自由文本字段分配它们的值,这很简单。我如何将这个日期选择器 div 放入可以分配给我的 StartDate
属性 的表单域中?除了能够单击该框并弹出日期选择器组件的功能外,我还想保留当前日期选择器框的外观。
你能不能不这样做
<div class="form-group">
<div id="datepicker-group" class="input-group date" data-date-format="dd/mm/yyyy">
@Html.TextBoxFor(x => x.StartDate, new {@class="form-control" })
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>