Form Post data not in date format

I have the following:

  • CSHTML page with an Ajax.BeginForm containing a number of EJS controls
  • HttpMethod = "POST"
  • Post works correctly and packages the fields and values up correctly
  • The Controller method has this parameter: DateTime?[] DateRangeFixed

However, when I look at the Form Post data in the browser debug, I sometimes see the array doesn't have correctly formed dates in (and server side the array is empty):

This seems to be related to refreshing the page, and carrying out a second post. Has this been reported before?

Even when it works first time, C# can't cope with the date formatting / cultures. I understand why cultures is additional configuration, but very frustrating when you just want a couple of dates available server side.  


1 Reply 1 reply marked as answer

SP Sureshkumar P Syncfusion Team September 28, 2022 07:45 AM UTC

Hi Aubyn,

When passing the form post using submit button the posted date dateformat is related to the local system date format. When we change the component dateformat using format and culture property we need to pass the ShortDatePattern with respected culture to resolve the dateformat issue for the form post.

To know more about the above solution, please refer to the below documentation: https://stackoverflow.com/questions/528545/mvc-datetime-binding-with-incorrect-date-format

Find the code example:

public Startup(IConfiguration configuration)

        {

            Configuration = configuration;

            var cultureInfo = new CultureInfo("en-US");

            // set the format based on the component format property value

            cultureInfo.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";

            CultureInfo.DefaultThreadCurrentCulture = cultureInfo;

            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

        }


Regards,

Sureshkumar P


Marked as answer
Loader.
Up arrow icon