0

My page sends a form via $.get to an aspnet core action.

$("#submit-form").on("submit", function () {
    var form = $("#submit-form");
    var valuesToSubmit = form.serialize();

    $.get("/MyController/List", valuesToSubmit, function (response) {
        ....
    });     

    return false;
});

In this form this is a Date field that is in format: dd/mm/yyyy. The valuesToSubmit variable has this value:

Name=&DateBirth=05%2F08%2F1971&__RequestVerificationToken=CfDJ8DHb24pNxPVIkZwi2Mzh0aTz4ZPyAIDsVSVm7-KxVMiV17Z1Twov88zN3F-JwewrGHF9LWSkdp5eOks7KwTgHWRhkdE7N6vfBHeNviCNV1cQdHdW5zPQgk3EEFPN1Lqe0vBK9ay5vnc0oCYWWPPuYgmQTC65iYTy7-0oc0CskGJpul5eSwuS3hUMer4P6g16Ng

I typed 05/08/1971 but in the controller the date parameter comes as 08/05/1971

My action code:

public async Task<IActionResult> List(string name, DateTime? dateBirth)

Should I change something in the javascript or c# code?

Beetlejuice
  • 4,292
  • 10
  • 58
  • 84
  • What's your browser language and what's your windows language? – Haytam Sep 19 '18 at 12:25
  • This is a known scenario, lots of previous info online if you search about it. If you can, I would either use an unambiguous date format such as yyyy-mm-dd or use a POST request and make sure the server's culture settings would mean that the date format would be understood correctly. See https://stackoverflow.com/a/10519800/5947043 - it's for asp.net but the same will apply to Core I'm sure – ADyson Sep 19 '18 at 12:26
  • @ADyson, changing to "post" works. – Beetlejuice Sep 19 '18 at 13:00

0 Answers0