8

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.

7 Answers 7

11

Use jquery hosted by google.

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js">
</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" >
Sign up to request clarification or add additional context in comments.

3 Comments

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.
I give you the tick, as your solution worked though - pity my typing is so lame today...
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.
3

This blog post provides an excellent overview of integrating the jQuery datepicker into a MVC 3 site.

Some of other samples that I could find were focused on MVC1 and 2.

Comments

1

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.

1 Comment

Good advice. If you use IE, Microsoft Fiddler-fiddler2.com/fiddler2 is also useful for showing that script files are 404'ing.
0

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.

Comments

0

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

Comments

0

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.

Comments

0

Tabs

            UL.tabNavigation {
                list-style: none;
                margin: 0;
                padding: 0;
            }

            UL.tabNavigation LI {
                display: inline;
            }

            UL.tabNavigation LI A {
                padding: 3px 5px;
                background-color: #ccc;
                color: #000;
                text-decoration: none;
            }

            UL.tabNavigation LI A.selected,
            UL.tabNavigation LI A:hover {
                background-color: #333;
                color: #fff;
                padding-top: 7px;
            }

            UL.tabNavigation LI A:focus {
                    outline: 0;
            }

            div.tabs > div {
                    padding: 5px;
                    margin-top: 3px;
                    border: 5px solid #333;
            }

            div.tabs > div h2 {
                    margin-top: 0;
            }

            #first {
                background-color: #f00;
            }

            #second {
                background-color: #0f0;
            }

            #third {
                background-color: #00f;
            }

            .waste {
                    min-height: 1000px;
            }
-->
</style>

<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<link href="CSS/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>

   <script  type="text/javascript">
       $(function() {
           $("#datepicker").datepicker();
       });

Date:

Download the js files from JQUERY and place them in a local folder on your machine, if you are using Visual Studio simply drag the file onto your designer surface. Don't forget to link the CSS file as well. What I do for every project is from my download location I add the js files into a folder called Scripts in my project, and css files in a folder called CSS.

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.