Wednesday, November 6, 2013

MVC4 with jquery-ui datepicker - Microsoft JScript runtime error: 'jQuery' is undefined

Working on a MVC project and making good progress.  Decided to start using jQuery and had real
issues using the datepicker.  Kept getting this error and new it had to be something with the order
and load time. 

Solution:
 1. Open your _layout.cs and add the following just before the closing tag of the </body>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Styles.Render("~/Content/themes/base/css")
    @RenderSection("scripts", required: false)
2. Finally to test your view, open your index.cshtml and add this at the end
<p>Date:
    <input type="text" id="txtDate" class="datefield" />
</p>

@section Scripts{
    @*@Scripts.Render("~/bundles/jqueryval")*@
    <script type="text/javascript">
        $(document).ready(function () {
            $(".datefield").datepicker();
        });
    </script>
}
 
source:

No comments:

Post a Comment