【发布时间】:2018-01-25 00:57:04
【问题描述】:
我遵循了这家伙的第三个解决方案:
https://blog.jigsawpieces.me/2014/07/23/lbd-adding-datetimepicker-control-to-mvc-project/
据说通过 Visual Studio 中的 Nuget 包管理器安装:
Install-Package Bootstrap.v3.Datetimepicker
然后将其添加到 Bundle.config:
bundles.Add(new ScriptBundle("~/bundles/moment").Include(
"~/Scripts/moment.js"));
我看到它在输入字段旁边显示日历图标,但是当我单击它时,日历不会下拉。这是我的 Bundle.config 文件:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/moment").Include(
"~/Scripts/moment.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/themes/base/jquery.ui.all.css",
"~/Content/site.css"));
}
这是显示此输入字段的视图:
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control datepicker" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker({ format: 'dd MM yyyy - hh:ii' });
});
</script>
</div>
我做错了什么?为什么日历不会下拉并显示日期选择器?
这是我的新 Bundle.config。我添加了其他 js 和 css 文件,但仍然没有:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/moment").Include(
"~/Scripts/moment.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap-datetimepicker.min.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-datetimepicker.min.css",
"~/Content/themes/base/jquery.ui.all.css",
"~/Content/site.css"));
}
【问题讨论】:
标签: jquery asp.net-mvc twitter-bootstrap datepicker