Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI datepicker in Asp.Net MVC

I have tried to use some of the widgets in JQuery UI on an Asp.Net MVC site without luck.

For example the basic datepicker from jQuery UI - functional demos.

I have created a simple MVC project and added the script references in Site.Master like this:

<script src="../../Scripts/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-personalized-1.5.3.min.js" type="text/javascript"></script>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/ui.datepicker.css" rel="stylesheet" type="text/css" />"

In the Index.aspx file I have cleared all default content and added the following:

<script type="text/javascript">
    $("#basics").datepicker();     
</script>  
<input type="text" size="10" value="click here" id="basics"/> 

The core jQuery works fine. Any clues?

like image 678
Frederik Avatar asked Dec 22 '08 00:12

Frederik


People also ask

How can set current date in DatePicker in MVC?

$(". date"). datepicker( "setDate", "@Model. Birthdate");

How to use DatePicker in ASP net c#?

If you are using HTML5 and . NET Framework 4.5, you can instead use an ASP.NET TextBox control and set the TextMode property to "Date", "Month", "Week", "Time", or "DateTimeLocal" -- or if you your browser doesn't support this, you can set this property to "DateTime".

What is DatePicker in jQuery?

A date-picker of jQuery UI is used to provide a calendar to the user to select the date from a Calendar. This date picker usually connected to a text-box so user selection of date from the calendar can be transferred to the textbox.


2 Answers

Make sure your initializer is called after the DOM is loaded:

$(document).ready(function() {
    $("#basics").datepicker();
});

jQuery ready event:

By using this method, your bound function will be called the instant the DOM is ready to be read and manipulated, which is when 99.99% of all JavaScript code needs to run.

like image 175
Frank Krueger Avatar answered Oct 04 '22 12:10

Frank Krueger


I've got a write-up of this with MVC 3 here: http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx

like image 27
Stuart Leeks Avatar answered Oct 04 '22 11:10

Stuart Leeks