Introduction
In this article we will learn about how to add Datepicker in our ASP.Net MVC project. We will use Jquery UI to add Datepicker in our project. In this project I am binding Datepicker with my model class property. You can even bind it with your Database model class property.
Prerequisite
If you don't know about the basics of an ASP.Net MVC project then please check my previous article; it will help you a lot.
Procedure
Let's start our project in ASP.Net MVC.
- Create a new project in ASP.Net web Application.
- Select MVC as a template.
- Add new controller into a controller folder and name it as peryour requirement (my controller name : DatepickerController).

Next we have to add one class inside a model folder. If you want to get and set data of datepicker from your Database table class then you don't need to add a new model class.
After adding model class you have to add property into it.

Now we have to add view so right click on index then add view. Set the parameters according to the picture below.

Next we download JquerUI (Combined library) from nuget package.
So follow the steps:
Tools -> NuGet Package Manager -> Manage NuGet Package Solution -> Search "Jquery UI" Download it.

Now you arrive at a view page and add the information accordingly.

Jquery code
- <script>
- $(document).ready(function () {
- $(".datepicker").datepicker({
- dateFormat: "dd-mm-yy",
- changemonth: true,
- changeyear: true
- });
- });
- </script>
And we have to check that RenderSection is present and not in a layout file.

Now we are finished with our project. Thanks for reading and happy learning.
Output


Nilesh SawardekarPosted Dec 6, 2022, 5:22 AM
Also, you may need to add <script src="~/Scripts/jquery-3.6.1.min.js"></script> or your version of jquery min js file on the top of jquery.ui
Claudio La RoccaPosted Dec 1, 2022, 5:41 PM
There is any way to select time also? Thank you
Mudzakkir TohaPosted Dec 24, 2021, 7:37 AM
Same with "coding Neas", where is .js and .css located? Finally, I download manually jQuery UI.. and copy .css and .js from downloaded jquery-ui.zip to my project
mpumi mokoenaPosted Aug 3, 2021, 11:47 AM
Thank you, awesome Code
Coding NeasPosted Jul 17, 2021, 2:21 PM
What do you mean in point 3 by saying: Drag and drop the .css and .js file from here according to there location. Which file? Which location?
Laxmidhar SahooPosted Jul 2, 2020, 4:14 AM
Thanks a good article for ading jquery datatime picker .So can customized it
Farhan AhmedPosted Jul 1, 2020, 10:24 AM
Just add @type="date" attribute in html helper you need not to add jquery HTML 5 datepicker will available to use.