This is a migrated thread and some comments may be shown as answers.

The value dd/MM/yyyy not valid

9 Answers 1868 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 25 May 2016, 02:06 PM

I have a editable Kendo grid with two datepicker inside, the kendo grid and it's controller are part an MVC Area. When i want to save a row the error is shown saying that the value introduced is not valid, i want the date format as dd/MM/yyyy. Those date fields have a template like this:

 

@(Html.Kendo().DatePicker()
        .Name("date")
        .Culture("es-MX")
        .Format("{0:dd/MM/yyyy}")
        .ParseFormats(new string[] { "dd/MM/yyyy" })
)

 

also in the columns definition have format and even a js function to get the value as i want

.Columns(columns =>
    {
        columns.Bound(p => p.InicioVigencia).Format("{0:dd/MM/yyyy}").ClientTemplate("#=getDate(InicioVigencia)#");
        columns.Bound(p => p.FinVigencia).Format("{0:dd/MM/yyyy}").ClientTemplate("#=getDate(FinVigencia)#");

}

function getDate(object) {
            if (object == null || object == "null" || object == "NULL" || object == "Null")
                return "";
            return kendo.toString(object, "dd/MM/yyyy");
        }

 

In the global.asax i set this properties in order to have the date format i want.

CultureInfo threadCultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
            CultureInfo uiCultureInfo = (CultureInfo)CultureInfo.CurrentUICulture.Clone();

            threadCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
            threadCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";
            uiCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
            uiCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";

            Thread.CurrentThread.CurrentCulture = threadCultureInfo;
            Thread.CurrentThread.CurrentUICulture = uiCultureInfo;

But the system still showing the error, i have other datepickers defined as js in orther controller just like this

$(function () {
        $(".date-picker").kendoDatePicker({
            animation: {
                close: {
                    effects: "fadeOut zoom:out",
                    duration: 300
                },
                open: {
                    effects: "fadeIn zoom:in",
                    duration: 300
                }
            },
            format: "dd/MM/yyyy",
            culture: "es-MX"
        });
    });

And everyting is working fine, so i don't know why it is not working properly. if i change global.asax like this

CultureInfo threadCultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
            CultureInfo uiCultureInfo = (CultureInfo)CultureInfo.CurrentUICulture.Clone();

            threadCultureInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
            threadCultureInfo.DateTimeFormat.LongDatePattern = "MM/dd/yyyy hh:mm:ss tt";
            uiCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
            uiCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";

            Thread.CurrentThread.CurrentCulture = threadCultureInfo;
            Thread.CurrentThread.CurrentUICulture = uiCultureInfo;

the grid that use the templates work properly but the view with the js stop working

9 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 26 May 2016, 08:03 AM
Hello,

I would suggest you to follow the steps for changing the culture described here and verify if the problem still exists? Note, you should set the culture by calling kendo.culture as it is demonstrated below:
<script>
 kendo.culture("es-MX");
 </script>

Additionally, I would suggest you to review this blog post.

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Victor
Top achievements
Rank 1
answered on 26 May 2016, 01:08 PM

The project already have all that. this is the bundle:

bundles.Add(new ScriptBundle("~/bundles/kendo/2016.1.226/kendo").Include(
                      "~/Scripts/kendo/2016.1.226/kendo.all.min.js",
                      "~/Scripts/kendo/2016.1.226/kendo.web.min.js",
                      "~/Scripts/kendo/2016.1.226/kendo.aspnetmvc.min.js",
                      "~/Scripts/kendo/2016.1.226/cultures/kendo.culture.es-MX.min.js",
                      "~/Scripts/kendo/2016.1.226/messages/kendo.messages.es-ES.min.js"));

And this is the _Layout.cshtml

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - Recinto Fiscalizado</title>
    @Styles.Render("~/Content/styles")
    @Styles.Render("~/Content/kendo/2016.1.226/kendoStyles")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/kendo/2016.1.226/kendo")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/cldr")
    @Scripts.Render("~/bundles/globalize")
    @RenderSection("Scripts", required: false)
    <script>
  kendo.culture("es-MX");
    </script>
</head>

 

But even with this the error persist

0
Milena
Telerik team
answered on 30 May 2016, 07:48 AM
Hello,

It is hard to find the reason for the unwanted behavior based on the provided information. Can you isolate the issue in a small runnable project and we will debug it locally?

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Victor
Top achievements
Rank 1
answered on 07 Jun 2016, 02:39 PM

Hi this is a new project that has the same issue, the save and edit fuction don't have a functionality they just return an empty list, how ever each time you click save the model state has an error an the date received is 01/01/0001.

https://mega.nz/#!5Y80iBAQ!LF39JCtn9uL4na2NAyTUHV_W9UUrS30bDx6WuconCIM

I add it as a external link as this page only admit 2Mb files and even in a zip file is dificult to compress a full project

0
Milena
Telerik team
answered on 08 Jun 2016, 08:07 AM
Hello Victor,

Can you modify the web.config as use the code below and verify how it works on your end?

<globalization culture="es-MX" uiCulture="es-MX" enableClientBasedCulture="false" />


Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Victor
Top achievements
Rank 1
answered on 08 Jun 2016, 01:54 PM
Hi, i have tried changing the webconfig as you suggested but the problem persist.
0
Milena
Telerik team
answered on 09 Jun 2016, 04:06 PM
Hello,

The single change I performed to your project is the change of "culture=es" to culture="es-MX" in web.config file. In the video recorded, you can see the data is valid. Can you explain what is the difference when the same steps are performed on your end?

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Victor
Top achievements
Rank 1
answered on 10 Jun 2016, 04:10 PM
This is really weird cause the code is the same, but the system still showing me the error.
0
Victor
Top achievements
Rank 1
answered on 13 Jun 2016, 04:14 PM

I Finally found a solution, i add some js to change date format using toISOString() function.

Everything based in this post http://www.telerik.com/forums/complex-object-post-issues-with-datetime-property

This is my grid binding

.Read(read => read.Action("TDESYCON_Read", "TarifasDESYCON").Data("sendAntiForgery"))
        .Create(create => create.Action("TDESYCON_Create", "TarifasDESYCON").Data("sendAntiForgery"))
        .Update(update => update.Action("TDESYCON_Edit", "TarifasDESYCON").Data("sendAntiForgery"))

and this is the function sendAntiForgery

function sendAntiForgery(data) {
            if (data.models) {
                data.models[0].InicioVigencia = data.models[0].InicioVigencia.toISOString();
                data.models[0].FinVigencia = data.models[0].FinVigencia.toISOString();
            }
            return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
        }

Like this i can send the date in a format MVC Controller can understand

 

Tags
Date/Time Pickers
Asked by
Victor
Top achievements
Rank 1
Answers by
Milena
Telerik team
Victor
Top achievements
Rank 1
Share this question
or