[英]Bootstrap 3 Datetimepicker not showing in an ASP.NET MVC application
I know this is a common problem, but I have scoured all the other questions and tried all possible solutions. 我知道这是一个常见问题,但是我已经搜寻了所有其他问题并尝试了所有可能的解决方案。
I'm trying to implement a simple Bootstrap 3 datetimepicker in an MVC 5 application, but can't get it to show. 我正在尝试在MVC 5应用程序中实现一个简单的Bootstrap 3 datetimepicker,但无法显示它。 The default browser datepicker works, but when I try to use bootstrap, I get a simple text-box with nothing else.
默认的浏览器日期选择器有效,但是当我尝试使用引导程序时,我得到了一个简单的文本框,没有其他任何内容。
I used NuGet to download the required packages: 我使用NuGet下载所需的软件包:
Install-Package Bootstrap.v3.Datetimepicker.CSS
This is my model: 这是我的模型:
[DataType(DataType.DateTime)]
[Display(Name = "Due Date")]
[DisplayFormat(DataFormatString = "{0:G}",
ApplyFormatInEditMode = true)]
public DateTime DueDate { get; set; }
This is my view: 这是我的看法:
<div class="form-group">
@Html.LabelFor(model => model.DueDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.DueDate, new { @class = "form-control datetimepicker " })
@Html.ValidationMessageFor(model => model.DueDate, "", new { @class = "text-danger" })
</div>
</div>
This is my BundleConfig.cs file: 这是我的BundleConfig.cs文件:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
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/themes/base/jquery.ui.all.css",
"~/Content/bootstrap-datetimepicker.min.css",
"~/Content/site.css"));
bundles.Add(new ScriptBundle("~/bundles/moment").Include(
"~/Scripts/moment.js"));
This is what I have at the bottom of my view (Index.cs) to start the javascript: 这是我在视图底部(Index.cs)中启动javascript的内容:
@section scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(function () {
$('.datetimepicker').datetimepicker();
});
</script>}
Am I missing something? 我想念什么吗?
Any kind of help would be very much appreciated! 任何帮助将不胜感激!
Turns out I had forgotten to render the bundles, so adding @Scripts.Render("~/bundles/bootstrap")
solved the issue. 原来我忘了渲染捆绑包,所以添加
@Scripts.Render("~/bundles/bootstrap")
解决了这个问题。 Thank you very much Stephen Muecke and Alexander Derc! 非常感谢Stephen Muecke和Alexander Derc!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.