In this article I will explain with an example, how to implement jQuery DatePicker in ASP.Net Core MVC.
 
 
Controller
The Controller consists of following two Action methods.
Action method for handling GET operation
Inside this Action method, simply the View is returned.
 
Action method for handling POST operation
This Action method gets called when the Button is clicked.
Inside this Action Method, the value of the selected Date is fetched and set into a ViewBag object.
public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
 
    [HttpPost]
    public IActionResult Index(string selectedDate)
    {
        DateTime dt = Convert.ToDateTime(selectedDate);
        ViewBag.Message = "Selected Date: " + dt.ToShortDateString();
        return View();
    }
}
 
 
View
Inside the View, first the ASP.Net TagHelpers is inherited.
The View consists of an HTML Form which has been created using the ASP.Net TagHelpers with the following attributes.
asp-action – Name of the Action. In this case the name is Index.
asp-controller – Name of the Controller. In this case the name is Home.
method – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
Inside the Form, there is a TextBox and a Submit Button.

jQuery DatePicker Plugin implementation
Inside the View, the following CSS file is inherited.
1. jquery-ui.css
 
And then, the following JS scripts are inherited.
1. jquery.min.js
2. jquery-ui.min.js
The jQuery DatePicker plugin has been assigned following properties:
showOn – button
The jQuery DatePicker will be shown only when the Button next to the TextBox is clicked.
buttonImageOnly – true
The Button will be an Image.
buttonImage – URL
The URL of the Image file to be displayed as Button.
dateFormat – mm/dd/yy
The jQuery DatePicker will set the selected Date in MM/dd/yyyy date format in TextBox.
 
Submitting the Form
When the Date and is selected and the Submit button is clicked, the Form is submitted and the ViewBag object is checked for NULL and if it is not NULL then, the value of the ViewBag object is displayed using JavaScript Alert Message Box.
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <form method="post" asp-controller="Home" asp-action="Index">
        <input type="text" id="txtDate" name="selectedDate" />
        <input type="submit" value="Submit" />
    </form>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtDate").datepicker({
                showOn: 'button',
                buttonImageOnly: true,
                buttonImage: 'images/calendar.gif',
                dateFormat: 'mm/dd/yy'
            });
        });
    </script>
    @if (ViewBag.Message != null)
    {
        <script type="text/javascript">
            window.onload = function () {
                alert("@ViewBag.Message");
            };
        </script>
    }
</body>
</html>
 
 
Screenshots
The Form
ASP.Net Core: Implement jQuery DatePicker
 
DateTime object displaying the selected DateTime
ASP.Net Core: Implement jQuery DatePicker
 
 
Demo
 
 
Downloads