[英]Bootstrap 3 Datetimepicker not showing in an ASP.NET MVC application
我知道這是一個常見問題,但是我已經搜尋了所有其他問題並嘗試了所有可能的解決方案。
我正在嘗試在MVC 5應用程序中實現一個簡單的Bootstrap 3 datetimepicker,但無法顯示它。 默認的瀏覽器日期選擇器有效,但是當我嘗試使用引導程序時,我得到了一個簡單的文本框,沒有其他任何內容。
我使用NuGet下載所需的軟件包:
Install-Package Bootstrap.v3.Datetimepicker.CSS
這是我的模型:
[DataType(DataType.DateTime)]
[Display(Name = "Due Date")]
[DisplayFormat(DataFormatString = "{0:G}",
ApplyFormatInEditMode = true)]
public DateTime DueDate { get; set; }
這是我的看法:
<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>
這是我的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"));
這是我在視圖底部(Index.cs)中啟動javascript的內容:
@section scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(function () {
$('.datetimepicker').datetimepicker();
});
</script>}
我想念什么嗎?
任何幫助將不勝感激!
原來我忘了渲染捆綁包,所以添加@Scripts.Render("~/bundles/bootstrap")
解決了這個問題。 非常感謝Stephen Muecke和Alexander Derc!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.