views:

3687

answers:

6

Ok, so I'm new to ASP.NET MVC and JQuery.

I have followed the following example to the letter, and I'm not able to get the datepicker working:

http://codesprouts.com/post/Creating-A-DatePicker-Extension-In-ASPNet-MVC.aspx

Can anyone tell me if there are any ticks or gotchas with this?

Bernard.

A: 

Without more specific info it's hard to tell what's going wrong.

One obvious thing to get you started, make sure that the src tags for your script files are correct. The filename name of the jquery-ui .js file changes if you download a standard or custom version, so it's worth double checking that the script tags in your code match the names of the files. The 'Net' tab of the firebug addon for Firefox is a real help for quickly spotting files your page can't find - it highlights any unfound files in red - generally saves a lot of time.

Steve Willcock
Good advice. If you use IE, Microsoft Fiddler-http://www.fiddler2.com/fiddler2/ is also useful for showing that script files are 404'ing.
RichardOD
A: 

See if you can get the datepicker working first in HTML only. That way you can eliminate errors introduced by incorrect file name in src tags, etc. Once you have that working you should be able to add it to the MVC solution the article describes.

David Robbins
+1  A: 

Use jquery hosted by google.

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;
</script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"&gt;
</script>

You will also need to link to your desired css.

$().ready(function()
{
    $('#from').datepicker({ dateFormat:'yy-mm-dd' });
});

<html>
...
<input id="from" class="date-field" name="from" type="text" >
David Liddle
Tried this, works well, but I'm not entirely comfortable with having the data picke hosted at Google. Irrational fear really, as I guess if Google we're to go offline anytime soon it would be due so an associated with a more serious issue such as asteroid stike or something. Anyway, it frustrated me that I wasn't able to get the thing going locally and I didn't want to give us, so just I didn't use this solution, even though it worked.
Bernard
I give you the tick, as your solution worked though - pity my typing is so lame today...
Bernard
I've tried including these jQuery scripts to my site.master, but now I get a blue screen. The html is there if I view source, but this happens without actually calling any javascript.Taking out the reference to jquery-1.3.2.min.js gets the page content showing up again.
marcel_g
A: 

I've had difficulty in the past using the jQuery datepicker when I was using the entire jquery UI css in one file. what I ended up doing, and what seemed to work for me, was to include the different jQuery UI CSS files separately, as needed, in my page or master page. When I included the datepicker in a separate CSS file, it worked.

YMMV

Todd Brooks
A: 

One thing I found is if your id has square brackets or dots, then datepicker wont work. Try to replace them with under score or something else.

TwinForms
A: 
DBman