1

This is my Layout page in ASP.NET MVC 5 project :

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - Fabricator</title>

    @Styles.Render("~/Content/jqueryui")
    @Styles.Render("~/Content/css")

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/bootstrap")
</head>
<body>

    <div class="container body-content">

        @RenderBody()
    </div>




    <script type="text/javascript">
        $(function () {
            // This will make every element with the class "date-picker" into a DatePicker element
            $('.date-picker').datepicker({ dateFormat: "mm-dd-yy" });
        })
    </script>

    @RenderSection("scripts", required: false)
</body>
</html> 

I call datepicker like this :

<div class="form-group">

    <label class="control-label col-md-2" for="ProjectDeadline">Project Deadline : </label>
    <div class="col-md-10">
        @Html.TextBoxFor(model => model.ProjectDeadline, new { @class = "date-picker"})
        @Html.ValidationMessageFor(model => model.ProjectDeadline)
    </div>
</div>

I have this in the model :

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString =
   "{0:MM-dd-yyyy}",
    ApplyFormatInEditMode = true)]
public DateTime ProjectDeadline { get; set; }

This code works perfectly on IE and Chrome, but when I click Create, it says

The field ProjectDeadline must be a date.

Can you tell me how to fix this? Thanks.

jason
  • 6,962
  • 36
  • 117
  • 198

0 Answers0