我正在構建一個MVC 5應用程序,我正在嘗試使用Bootstrap.v3.Datetimepicker.CSS。MVC 5 Bootstrap.v3.Datetimepicker.CSS錯誤:對象不支持屬性或方法'datetimepicker'
我有
$(document).ready(
function() {
$('.datetimepicker').datetimepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd/mm/yyyy"
});
});
這是我的包怎麼看起來像
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
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/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap-datepicker.js",
"~/Scripts/DatePickerReady.js",
"~/Scripts/respond.js"));
bundles.Add(new ScriptBundle("~/bundles/moment").Include(
"~/Scripts/moment.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-datetimepicker.min.css",
"~/Content/site.css"));
// Set EnableOptimizations to false for debugging. For more information,
// visit http://go.microsoft.com/fwlink/?LinkId=301862
BundleTable.EnableOptimizations = true;
這是視圖
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>CreateEditSeasonViewModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.StartDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.StartDate, new { htmlAttributes = new { @class = "form-control datetimepicker", placeholder = "Enter start date here..." } })
@Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EndDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EndDate, new { htmlAttributes = new { @class = "form-control datetimepicker", placeholder = "Enter end date here..." } })
@Html.ValidationMessageFor(model => model.EndDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
當我運行該應用程序我得到一個JavaScript文件這個錯誤在IE 11和Firefox中。
我在做什麼錯,我該如何擺脫這個障礙?
更新:我跟隨了一些博客,包括這些;
adding-datetimepicker-control-to-mvc-project
您的datetimepicker文件名爲'bootstrap-datetimepicker.js'嗎?檢查你的腳本文件夾,然後檢查你的捆綁包。 – Jasen 2015-02-10 00:00:40
@Jasen datetimepicker是該組中js函數的一部分(bootstrap包)。我將文件命名爲DatePickerReady – Komengem 2015-02-10 00:03:41
因此,您將'bootstrap-datetimepicker.js'重命名爲'DatePickerReady.js'?加載頁面資源時你有404s嗎? – Jasen 2015-02-10 00:08:54