In this article I will explain with an example, how to implement jQuery DateTimePicker in ASP.Net MVC.
 
 
Download jQuery DateTimePicker Plugin
You will need to download the plugin files from the following location.
The complete documentation is available on the following page.
 
 
View
The View consists of an HTML Form which has been created using the Html.BeginForm method with the following parameters.
ActionName – Name of the Action. In this case the name is Index.
ControllerName – Name of the Controller. In this case the name is Home.
FormMethod – 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 created using the MVC Helper method and a Submit Button.
 
jQuery DateTimePicker Plugin implementation
Inside the View, the following CSS file is inherited.
1. jquery.datetimepicker.css
 
And then, the following JS scripts are inherited.
1. jquery.min.js
2. jquery.datetimepicker.full.js
Inside the jQuery document ready event handler, the TextBox has been applied with the jQuery DateTimePicker plugin.
 
Submitting the Form
When the Date and Time 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 MessageBox.
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        @Html.TextBox("SelectedDateTime", "", new { @id = "txtDateTime" })
        <input type="submit" value="Submit" />
    }
 
    <link href="/plugin/jquery.datetimepicker.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="/plugin/jquery.datetimepicker.full.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtDateTime").datetimepicker();
        });
    </script>
 
    @if (ViewBag.Message != null)
    {
        <script type="text/javascript">
            $(function () {
                alert("@ViewBag.Message");
            });
        </script>
    }
</body>
</html>
 
 
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 Form is submitted.
Inside this Action Method, the value of the selected Date and Time is fetched and set into a ViewBag object.
public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        return View();
    }
 
    [HttpPost]
    public ActionResult Index(string selectedDateTime)
    {
        DateTime dt = Convert.ToDateTime(selectedDateTime);
        ViewBag.Message = "Selected Date and Time: " + dt.ToString();
        return View();
    }
}
 
 
Screenshots
The Form
Implement jQuery DateTimePicker in ASP.Net MVC
 
DateTime object displaying the selected DateTime
Implement jQuery DateTimePicker in ASP.Net MVC
 
 
Downloads