首页 文章

mvc bootstrap datepicker与编辑器模板不工作

提问于
浏览
1

我尝试在我的mvc项目中使用实现bootstrap v3 datetimepicker,但它不起作用 . 下面是我的编辑模板 .

@model DateTime? @ Html.TextBox(“”,Model.HasValue?Model.Value.ToString(“d”):String.Empty)

$(function(){
//仅定位此编辑器模板中的输入
$( '#日期选择器')的DateTimePicker() .
}); </ SCRIPT>

我在我的_layout.chtml上安装了bootstrap datetimepicker脚本,但似乎无法正常运行

<script src =“〜/ Scripts / bootstrap-datetimepicker.js”> </ script>

<script src =“〜/ Scripts / bootstrap-datetimepicker.min.js”> </ script> 这是我的看法 > @ Html.LabelFor(model => model.EndDate,new {@class =“control-label col-md-2”})@ Html.EditorFor(model => model.EndDate)@ Html.ValidationMessageFor(model => model.EndDate) </ DIV> </ DIV> 如果我将其设置为,它只会作为普通的datetimepicker出现 > [DataType(DataType.Date)] public DateTime EndDate {get;组; }

3 回答

  • 0

    使用

    $(function() {
        // target only the input in this editor template
        $('#EndDate').datetimepicker();
    });
    
  • 0
    • 您不必同时包含min.js和.js删除一个 .

    • 为CSS添加〜/ Content / bootstrap-datepicker.css

    @Html.LabelFor(model => model.EndDate)
    @Html.TextBoxFor(model => model.EndDate, new { @class = "form-control datepicker", placeholder = "Palce holder of your choice" })
    @Html.ValidationMessageFor(model => model.EndDate)
    

    初始化后,其余代码将继续工作

    $(function() {
      // target only the input in this editor template
      $('#datepicker').datetimepicker();
    });
    
  • 0

    到目前为止,有许多bootstrap datetimepickers . 所以,你必须指定你正在使用的正确的datetimepicker . 如果是这个 - http://eonasdan.github.io/bootstrap-datetimepicker/

    然后,包括

    • 包括moment.js文件 - http://momentjs.com/downloads/moment.js

    • 摆脱了一个datetimepicker javascript文件(〜/ Scripts / bootstrap-datetimepicker.js或〜/ Scripts / bootstrap-datetimepicker.min.js)

    • 包括datetimepicker css文件 .

    • 在视图文件中添加此脚本 .

    $(function(){$('#ID_of_the_Input') . datetimepicker();});

相关问题