JQuery UI datepicker in Asp.Net MVC

javascript

To use the jQuery UI datepicker in an ASP.NET MVC application, you can follow these steps:

  1. Install the jQuery.UI.Combined NuGet package in your project.

  2. In your view, include the necessary CSS and JavaScript files for jQuery and jQuery UI:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-3.5.1.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  1. In your view, add an input field with a unique ID:
<input type="text" id="datepicker" />
  1. In a script block at the bottom of your view, initialize the datepicker:
<script>
    $(function() {
        $("#datepicker").datepicker();
    });
</script>

That’s it! Now when you load your view, the datepicker should be available for use. You can customize the date format, language, and other options by passing them as parameters to the datepicker function.