0

I am working on an asp.net mvc-4 web application. and i have the following field inside my view:-

 <div >
     <span class="f"> @Html.DisplayNameFor(model => model.CustomerApprovalDate) </span> 
@Html.TextBoxFor(model => model.CustomerApprovalDate, new { @class = "datepicker" ,@Value =Model != null ? Model.CustomerApprovalDate.ToString("dd-mm-yy"):string.Empty}) 
    @Html.ValidationMessageFor(model => model.CustomerApprovalDate)
</div>

and i define the following jquery datepicker:-

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">

    $(document).ready(function () {
        $(".datepicker").datepicker({
            dateFormat: 'dd-mm-yy',
            showOn: "both"
        });

currently when i try to enter a date such as 31 05 2016 ,, i will get the following error when i try submitting the form :-

enter image description here

John John
  • 1
  • 72
  • 238
  • 501
  • Is your model type DateTime? – threesixnine May 13 '16 at 16:40
  • @NaughtyNinja yes it is here is my model property [Display(Name = "Customer Approval Date")] [Required] [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:dd-MMM-yyyy}")] public System.DateTime CustomerApprovalDate { get; set; } – John John May 13 '16 at 16:58
  • Since you are already setting a date format in jquery don't do it in your model, the problem could be that those two don't match and that is th reason why the validation cannot be passed successfully. – threesixnine May 13 '16 at 17:04
  • @NaughtyNinja but i am using the same Html.TextboxFor inside my create and my edit views.. so if i remove the format from the Html.TextBoxfor then inside my edit view the date will be rendered with time of 00:00:00 ... that why i define the format on the html itself .. – John John May 13 '16 at 17:11

0 Answers0