May 05, 2014 by Anuraj
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 :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub