0

I have in model DateTime

public System.DateTime date_in { get; set; }

And this is its View:

 <div class="form-group">
        @Html.LabelFor(model => model.date_in, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.date_in, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.date_in, "", new { @class = "text-danger" })
        </div>
    </div>

when I just click the EditorFor() to change the date, It writes:

The field date_in must be a date.

all formats I tried to insert (with time and without and change the places of month and day) were wrong.

The individual way I succeeded is when month value and day value smaller than 13
I have tried answers people answered on similar questions like add globalization tag and custom binder but nothing helped me.

yan
  • 21
  • 1
  • Did you try `[DataType(DataType.Date)]`? http://stackoverflow.com/a/12634470/5112433 – Ilya Chumakov May 22 '16 at 06:17
  • I tried now. your suggesion seems can help for Create but not for Edit, because it didn't shows me any date – yan May 22 '16 at 06:23
  • What is the culture on your server? –  May 22 '16 at 06:24
  • no defined culture in – yan May 22 '16 at 06:25
  • The `1/30/2016` will work fine but `30/1/2016` will not. And using `[DataType(DataType.Date)]` is only supported in Chrome and Edge and if you use it you must also use `[DisplayFormat(DateFormatString = "{0:yyyy-MM-dd}", ApplyInEditModel = true)]` –  May 22 '16 at 06:27
  • sorry, does not work – yan May 22 '16 at 08:23
  • Set the culture in you web config file to `en:US` and it will work fine! And if it not working for you then you have other errors in your code that you have not shown us. –  May 22 '16 at 13:14

0 Answers0