0

I wish to include datetimePicker in one of my form fields.

I followed the installation guide on this link: https://eonasdan.github.io/bootstrap-datetimepicker/Installing/ and accordingly added the required files to one of my partial views

Below is what I already have:

_PartialView

                           <link href="~/Content/bootstrap-datetimepicker.css" rel="stylesheet" />
<link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
        <script src="../../Content/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/Scripts/moment.js"></script>
<script src="~/Scripts/moment.min.js"></script>
     <script src="~/Scripts/bootstrap.js"></script>
<script src="../../Content/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script src="~/Scripts/bootstrap-datetimepicker.min.js"></script>

html code:

                            <div class="form-group">
                            @Html.LabelFor(Model => Model.Personne.DateNaissance, new { @class = "control-label", style = "" })

                            <div class='input-group date'>
                                @Html.TextBoxFor(Model => Model.Personne.DateNaissance, new { @class = " form-control", id = "datetimepicker1", placeholder = "AAAA-MM-JJ", onclick = "javascript:dateTimePicker()" })
                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                            </div>
                        </div>

JS code:

function dateTimePicker() {
    alert("bonjour eunice");
    $('#datetimepicker1').datetimepicker({
        format: "dd/mm/yyyy",
        autoclose: true,
        todayHighlight: true
    });
}

I expect to see the datetimepicker display when I click on the date field, but nothing appears. No calendar, no nothing. Kindly help. Thanks

Nice Kloe
  • 59
  • 1
  • 10
  • You really shouldn't be putting java-script files into partial views. You're also loading the same JS files multiple times both the normal js file and the minified versions. – Nathan Champion Jan 16 '19 at 15:22
  • @NathanChampion i'm including the files in a partial view because I do not have a main layout page or an index page in my project. I guess I should create one into which I will include the files, for the datetimepicker to work, right? Is there not another solution, please? – Nice Kloe Jan 17 '19 at 17:42
  • Then you should be using a normal View not Partial View. Partial Views are for reusing the same snippet in multiple locations. – Nathan Champion Jan 17 '19 at 18:12
  • @NathanChampion, thanks for your response! – Nice Kloe Jan 22 '19 at 14:09

0 Answers0