1

I changed the culture in my Web.config file to es-CL, and the server side validation is working well, but whem i'm trying to submit the data the client side validation throws an error for dates like 25/11/2016 because it's still using the english date format like 11/25/2016.

I found this post wich is about the same but with decimals instead date: MVC 3 jQuery Validation/globalizing of number/decimal field

The problem is all the answers there are out-dated, because the newer globalization plugin doesn't use globalization files anymore, like globalize.culture.es-CL.js does not exists in the package. (Or i'm missing something?)

How can i set the client side validation culture to es-CL or es-MX?

Here is my View code:

        <div class="form-group">
            @Html.LabelFor(model => model.ReleaseDate, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @* i set the @type = "text" because i will use a Jquery DatePicker instead the browser's DatePicker, and the @class = datepicker adds the DatePicker. *@
                @Html.EditorFor(model => model.ReleaseDate, new { htmlAttributes = new { @class = "form-control datepicker", @type = "text" } })
                @Html.ValidationMessageFor(model => model.ReleaseDate, "", new { @class = "text-danger" })
            </div>
        </div>

Model for that input:

[Display(Name ="Fecha de emisión")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}",ApplyFormatInEditMode = true)]
public DateTime ReleaseDate { get; set; }

Controller action:

public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Movie movie = db.Movies.Find(id);
            if (movie == null)
            {
                return HttpNotFound();
            }
            return View(movie);
        }

Thanks.

Community
  • 1
  • 1
  • Using `@Html.EditorFor()` and then `new { type = "text" }` makes no sense and it should be just `@Html.TextBoxFor(m => m.ReleaseDate, new { @class = "form-control datepicker"})`. And `[DataType(DataType.Date)]` and the `ApplyFormatInEditMode = true` property of `[DisplayFormat]` are only respected when using `EditorFor()` without overriding the `type` attribute so both should be deleted. –  Feb 06 '17 at 00:18
  • You need to override the `$.validator` (which validates dates based on `MM/dd/yyyy` format). Your `class="datepicker"` suggests you might be using a jquery plugin so refer [this answer](http://stackoverflow.com/questions/27285458/jquery-ui-datepicker-and-mvc-view-model-type-datetime/27286969#27286969) for the jquery-ui datepicker, or [this answer](http://stackoverflow.com/questions/39677035/date-of-birth-validation-keeps-showing/39682410#39682410) –  Feb 06 '17 at 00:23
  • Have you find the solution? I'm facing the exact same problem ... – Bozhidar Stoyneff Jul 24 '18 at 20:20

0 Answers0