The value dd/MM/yyyy not valid

10 posts, 0 answers
  1. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 25 May Link to this post

    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

  2. Milena
    Admin
    Milena avatar
    224 posts

    Posted 26 May Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 26 May in reply to Milena Link to this post

    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

  5. Milena
    Admin
    Milena avatar
    224 posts

    Posted 30 May Link to this post

    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
  6. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 07 Jun in reply to Milena Link to this post

    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

  7. Milena
    Admin
    Milena avatar
    224 posts

    Posted 08 Jun Link to this post

    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
  8. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 08 Jun in reply to Milena Link to this post

    Hi, i have tried changing the webconfig as you suggested but the problem persist.
  9. Milena
    Admin
    Milena avatar
    224 posts

    Posted 09 Jun Link to this post

    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
  10. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 10 Jun in reply to Milena Link to this post

    This is really weird cause the code is the same, but the system still showing me the error.
  11. Victor
    Victor avatar
    16 posts
    Member since:
    Nov 2015

    Posted 13 Jun in reply to Milena Link to this post

    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

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready