Reputation: 3515
I want to use jquery date picker on all datetime fields, so I have following inside my mvc3 project
Model
public DateTime? DateTime{ get; set; }
Views/Shared/EditorTemplates
@model DateTime?
@Html.TextBox("", Model.ToString(), new { @class = "date" })
and on _Layout.cshtml page I have
$(document).ready(function () {
$(".date").datepicker();
});
I have referenced datepicker css and other jquery files (jqueryui and jquery-1.5.1.js)
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />
error message is following
TypeError: $(".date").datepicker is not a function
[Break On This Error]
$(".date").datepicker();
Thanks
Upvotes: 1
Views: 1347
Reputation: 876
I have few suggestions.
Upvotes: 0
Reputation: 1038790
You seem to have included jquery
twice: the standard and the minified version. Get rid of one of the two. Also make sure that your custom script comes after them:
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".date").datepicker();
});
</script>
Upvotes: 1
Reputation: 2133
You didnt inculde the jQuery and jQuery UI(.js files not .css) libraries which this date picker belongs to.
Upvotes: 0