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?
$(". date"). datepicker( "setDate", "@Model. Birthdate");
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".
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With