Date not mapping to controller property kendodatepicker ASP.NET Core 6 MVC

51 Views Asked by At

The RequestedDate shows 1/1/0001 when submit the form. The reason is application culture is "en-US" and the format "dd/MM/yyyy" is not supported. I can not change the culture to "es-EC". Because if I set the culture to the "es-EC" then the NumericTextBoxFor post the value "169.90" to "16990".

@(Html.Kendo().NumericTextBoxFor(x=>x.UnitPriceAnalyticCost)
    .Format("c")
    .Events(x => x.Change("unitPriceChange")
    .Spin("unitPriceSpin"))
    .Spinners(false)
    .HtmlAttributes(new { style = "width:100%;cursor: not-allowed;pointer-events: none!important;color: black;font-color: black;background-color: #dddddd;", @readonly = true }))

@(Html.Kendo().DatePickerFor(m => m.RequestedDate)
        .Value(Model.RequestedDate)
        .Format("dd/MM/yyyy"))

Is it possible to map the "dd/MM/yyy" format datetime property value valid at the controller?

1

There are 1 best solutions below

0
sina_Islam On
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
      var customCulture = new CultureInfo("en-US");           
      customCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
      customCulture.NumberFormat.NumberDecimalSeparator = ".";

      CultureInfo.DefaultThreadCurrentCulture = customCulture;
      CultureInfo.DefaultThreadCurrentUICulture = customCulture;
}

This solve my issue. Though I can not use "es-EC".