I am formatting DateTime?
field like dd/MM/yyyy
and when I submit form it shows validation error.
I cannot get it why is it happens?
Model
[Display(Name = "Expected Ending Time")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime? ExpectedEndingTime { get; set; }
HTML
@Html.TextBoxFor(x => x.Requsition.ExpectedEndingTime, new { @class = "form-control dataPickerField", id = "ExpectedEndingTimeDataPicker", @readonly = true })
@Html.ValidationMessageFor(x => x.Requsition.ExpectedEndingTime)
<script>
$(function () {
$('#ExpectedEndingTimeDataPicker').datepicker({
format: 'dd/mm/yyyy',
autoclose: true
})
.on('changeDate', function (ev) {
// do things;
);
});
</script>
Nothing was useful for me guys....
So I added 1 extra field to the Model and will keep
DateTime
like aString
in the format I need.And for places I need
DateTime
format I have another field.