In this article I will explain with an example, how to implement Bootstrap DateTimePicker in ASP.Net MVC.
 
 
Download Bootstrap DateTimePicker Plugin
You will need to download the plugin files from the following location.
The complete documentation is available on the following page.
 
 
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();
    }
}
 
 
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.
The TextBox has been assigned Bootstrap classes and is associated with an HTML SPAN element which displays the FontAwesome Glyphicon Calendar Icon.
 
Bootstrap DateTimePicker Plugin implementation
Inside the View, the following CSS files are inherited.
1. bootstrap.min.css
2. font-awesome.min.css
3. bootstrap-datetimepicker.css
 
And then, the following JS scripts are inherited.
1. jquery.min.js
2. bootstrap.min.js
3. moment-with-locales.min.js
4. bootstrap-datetimepicker.min.js
Inside the jQuery document ready event handler, the TextBox has been applied with the Bootstrap DateTimePicker plugin and also the HTML SPAN element with class glyphicon-calendar has been assigned with jQuery Click event handler.
Inside the Click event handler, the focus function of the TextBox is called which displays the Bootstrap DateTimePicker Calendar.
 
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>
    <style type="text/css">
        body { padding: 20px; }
        .input-group { width: 210px !important }
    </style>
</head>
<body>
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        <div class="container">
            <div class="row">
                <div class='col-sm-6'>
                    <div class="form-group">
                        <div class='input-group date'>
                            @Html.TextBox("selectedDateTime", "", new { @id = "txtDateTime", @class = "form-control" })
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class='col-sm-6'>
                    <div class="form-group">
                        <input type="submit" id="btnSubmit" value="Submit" class="btn btn-primary" />
                    </div>
                </div>
            </div>
        </div>
    }
 
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtDateTime").datetimepicker();
            $('.glyphicon-calendar').click(function () {
                $("[id*=txtDateTime]").focus();
            });
        });
    </script>
 
    @if (ViewBag.Message != null)
   {
        <script type="text/javascript">
            window.onload = function () {
                alert("@ViewBag.Message");
            };
        </script>
    }
</body>
</html>
 
 
Screenshots
The Form
Implement Bootstrap DateTimePicker in ASP.Net MVC
 
DateTime object displaying the selected DateTime
Implement Bootstrap DateTimePicker in ASP.Net MVC
 
 
Demo
 
 
Downloads