Reputation: 21
I try to use implement bootstrap v3 datetimepicker in my mvc project but its not working. below is my editor templates.
@model DateTime?
@Html.TextBox("", Model.HasValue ? Model.Value.ToString("d") : String.Empty)
$(function() { // target only the input in this editor template $('#datepicker').datetimepicker(); }); </script>
i had inculded bootstrap datetimepicker script on my _layout.chtml but seem like it cant function
<script src="~/Scripts/bootstrap-datetimepicker.js"></script> <script src="~/Scripts/bootstrap-datetimepicker.min.js"></script>
this is my view
@Html.LabelFor(model => model.EndDate, new { @class = "control-label col-md-2" }) @Html.EditorFor(model => model.EndDate)
@Html.ValidationMessageFor(model => model.EndDate) </div> </div>
It only come out as normal datetimepicker if i set it as
[DataType(DataType.Date)] public DateTime EndDate { get; set; }
Upvotes: 1
Views: 2731
Reputation: 11
Use
$(function() {
// target only the input in this editor template
$('#EndDate').datetimepicker();
});
Upvotes: 0
Reputation: 358
there are many bootstrap datetimepickers to date. so, you have to specify the correct datetimepicker you're using. if its this - http://eonasdan.github.io/bootstrap-datetimepicker/
then, include
add this script in your view file.
$(function() {$('#ID_of_the_Input').datetimepicker();});
Upvotes: 0
Reputation: 2343
Add ~/Content/bootstrap-datepicker.css for CSS
@Html.LabelFor(model => model.EndDate)
@Html.TextBoxFor(model => model.EndDate, new { @class = "form-control datepicker", placeholder = "Palce holder of your choice" })
@Html.ValidationMessageFor(model => model.EndDate)
Rest of the code will work on once u initialize it
$(function() {
// target only the input in this editor template
$('#datepicker').datetimepicker();
});
Upvotes: 0