I have been stuck on this for an hour now.
I have a dynamic form. Which works fine when Adding New Items,
But then I try to submit the Form for Edit I get client side validation for DateTime:
This is the HTML:
using (Html.BeginCollectionItem("ValidDates"))
{
<div class="row mt-10">
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.IsDeleted, new { data_is_deleted = "false" })
<div class="col-md-5">
@Html.TextBoxFor(m => m.ValidFrom, new { @Value = Model.ValidFrom.ToString("dd/MM/yyyy"), @class = "form-control dateTimePicker" })
@Html.ValidationMessageFor(m => m.ValidFrom)
</div>
<div class="col-md-5">
@Html.TextBoxFor(m => m.ValidTo, new { @Value = Model.ValidFrom.ToString("dd/MM/yyyy"), @class = "form-control dateTimePicker" })
@Html.ValidationMessageFor(m => m.ValidTo)
</div>
<div class="col-md-1">
@Html.CheckBoxFor(m => m.Enabled)
</div>
<div class="col-md-1">
<span class="glyphicon glyphicon-trash" data-action="removeItem" title="remove" style="cursor:pointer"></span>
</div>
</div>
}
And this is the Model:
public class BucketValidDates : BaseEntity
{
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime ValidFrom { get; set; }
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime ValidTo { get; set; }
public bool Enabled { get; set; }
public virtual Bucket Bucket { get; set; }
[NotMapped]
public bool IsDeleted { get; set; }
}
I have even tried using EditorFor
(This works when I post Back but the DateFormat is not correct).
using (Html.BeginCollectionItem("ValidDates"))
{
<div class="row mt-10">
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.IsDeleted, new { data_is_deleted = "false" })
<div class="col-md-5">
@Html.EditorFor(m => m.ValidFrom, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ValidFrom)
</div>
<div class="col-md-5">
@Html.EditorFor(m => m.ValidTo, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ValidTo)
</div>
<div class="col-md-1">
@Html.CheckBoxFor(m => m.Enabled)
</div>
<div class="col-md-1">
<span class="glyphicon glyphicon-trash" data-action="removeItem" title="remove" style="cursor:pointer"></span>
</div>
</div>
}
I tried changing the format in Model to {0:dd/MM/yyyy}
I need the format to be: day/Month/Year
But as you can see in Image below that the Format is Year/Month/day
The DatePicker for this Project is: http://eonasdan.github.io/bootstrap-datetimepicker/
Does this datePicker have something to do with this?