3 Replies - 16339 Views - Last Post: 09 August 2012 - 01:06 PM

#1 BattlFrog  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 09-April 12

Using JQuery Datepicker with MVC3 and Razor

Posted 09 August 2012 - 07:56 AM

Hello and thank you for looking at my post. I am attempting to use the JQuery datepicker function in an MVC 3 application and I am unable to make it work. Here is some code:

_Layout.cshtml, Head section:

    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>

    <script lang="javascript" type="text/javascript">
        $(document).ready(function() {
            $("#PersonModel_DateofBirth").datepicker({ dateFormat: 'mm/dd/yyyy' });
        });    
    </script>




Here is the date of birth portion of the View:

             <div class="editor-label">
                @Html.LabelFor(model => model.PersonModel.DateofBirth)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.PersonModel.DateofBirth)
                @Html.ValidationMessageFor(model => model.PersonModel.DateofBirth)
            </div>  




and this is how it renders the code:

<input data-val="true" data-val-required="The DateofBirth field is required." id="PersonModel_DateofBirth" name="PersonModel.DateofBirth" type="text" value="" />



I have other custom javascript functions I wrote that are working fine, so I am not sure what I am missing here. Any tips, hints or suggestions would be greatly appreciated. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Using JQuery Datepicker with MVC3 and Razor

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: Using JQuery Datepicker with MVC3 and Razor

Posted 09 August 2012 - 12:59 PM

Jquery datepicker is part of the jquery ui library but I don't see a reference to a jquery ui javascript file anywhere.
Was This Post Helpful? 1
  • +
  • -

#3 BattlFrog  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 09-April 12

Re: Using JQuery Datepicker with MVC3 and Razor

Posted 09 August 2012 - 01:05 PM

Thanks Nakor, that did it. The styling is off though (no background). Do I need to style it myself or am I missing some other reference?
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: Using JQuery Datepicker with MVC3 and Razor

Posted 09 August 2012 - 01:06 PM

You're also using an older version of query which I've heard may not play nice with modernizer

You need to include the jquery ui stylesheet

This post has been edited by Nakor: 09 August 2012 - 01:06 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1