This post is about integrating JQuery UI DatePicker in MVC 4. First you need to modify the _layout.cshtml. Because by defualt, it won’t include required references for JQuery UI. You need to include both CSS and JS for JQuery UI references. So the modified _layout.cshtml will look like this.
And in the CSHTML where you want to include the JQuery Date Picker, include the following snippet.
Clicking on the textbox will popup calender like this.
It works perfectly, until validations come in to the play :) As my application is targeted to India / UK customers, I have added a formatting to DatePicker like this.
But MVC validator controls didn’t recognize the textbox value as a valid date time.
To resolve this issue, you need to override the date validation behaviour of JQuery validation library. You can do this by adding following snippet.
Also you need to add the Display Format attribute to the Model property.
Happy Programming :)
Did you like this article? Share it with your friends