Prakash Prakash - 1 month ago 23
jQuery Question

DateTimePicker is not showing

I am facing an issue with the datetime picker in jquery in MVC4. Here is my code:

@Html.TextBox("RELIEVING_DATE", Model.RELIEVING_DATE)


$(function () {
$("#RELIEVING_DATE").datepicker();
}


But the datetime picker is not showing and showing an error


Uncaught TypeError: Cannot read property 'inline' of undefined"


In my model
RELIEVING_DATE
is a nullable field. I want to give a default value to it.

Please help.

Answer

The first thing I notice in the script you posted is that your $(function () { is missing a closing ); at the end.

Also make sure you have properly included the jQuery and jQuery UI scripts in your page. If you are using bundles you might need to have the following scripts before the script that is attaching the date picker:

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")

Normally the ~/bundles/jquery bundle is already included in the _Layout.cshtml if you used the Internet Application Template to create your project.

Another thing you should verify is that you do not have multiple fields with the same id. Also if this @Html.TextBox is inside an editor template the id might not be #RELIEVING_DATE but prefixed with the navigational property, for example #SomeProperty_RELIEVING_DATE. Look at the generated HTML in the browser to see the exact id. You could also assign a class to the field:

@Html.TextBoxFor(x => x.RELIEVING_DATE, new { @class = "datepicker" })

and then:

$(function () {
    $('.datepicker').datepicker();
});