1

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

0

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

You didnt inculde the jQuery and jQuery UI(.js files not .css) libraries which this date picker belongs to.

2 Comments

actually I have included, just updated question with added js.
Your error message indicates absence of .Js files.Please check the jS files that you are including are getting included correctly on the page and also look if any of these files is not corrupt or blank.I think it should fix the problem.Or you can give us a URL to see this.
0

I have few suggestions.

  1. try updating jquery to the lates version which i think is 1.8.1
  2. i dont think you need model.tostring just model shoud work in this cale // dont think this is causing the issue but just a suggestion

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.