- Home
- Forum
- ASP.NET Core - EJ 2
- when posting DateTime is 01/01/0001
when posting DateTime is 01/01/0001
Hello,
I was experimenting with your library in order to replace my custom built components for DatePicker.
What I was expecting is inside a form if I have something like this:
<ejs-datepicker id="datepicker" action="@Model.NoviKlijent.DatumRodjenja" format="dd.MM.yyyy" placeholder="Enter date"></ejs-datepicker>
Displaying is working fine as you can see in attachment-1.png
but the issue with this is when I'm posting the form I'm getting wrong date parsed. Results are included in attachment2
I have also followed docs: https://ej2.syncfusion.com/aspnetcore/documentation/datepicker/globalization/
and I have included sr-Latn culture in a
Attachment: attachments_12059061.zip
SIGN IN To post a reply.
5 Replies
BC
Berly Christopher
Syncfusion Team
December 9, 2021 04:50 PM UTC
Hi Knilecrack,
Greetings from Syncfusion support.
We have validated the reported issue "While post, data received default value of DateTime type “01/01/0001” in controller" caused due to both server and client machine have a different date format. Because of this (“month and date order mismatch”), DatePicker component returns the value default value of the DateTime type “01/01/0001” in the POST action.
By default, the component rendered with “en-us” culture with “MM/dd/yyyy” date format. But (your) the machine configured with different culture with different date format.
During post-back time the date value sent as component date format value. In Server-side, the machine expects the date format as “dd/MM/yyyy” format. Both are mismatched so that the value was returned as 01/01/0001.
In this case, we can override this case by setting the locale property as per your culture or setting the date format equivalent of your culture date format in the sample level.
If you are using form post, date format set based on the globally defined culture (by default, en- US). So, we suggest you use the below work around solution in the Startup.cs file in your application to get the date value as per the defined format at your end.
Also, we suggest you to define the date value type as DateTime nullable as mentioned in the below code snippet.
|
public Startup(IConfiguration configuration)
{
Configuration = configuration;
var cultureInfo = new CultureInfo("sr");
cultureInfo.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
} |
|
public class DatePicker
{
[Required(ErrorMessage = "Please enter the value")]
public DateTime? value { get; set; }
} |
For your convenience, we have prepared the sample and attached it below.
Screenshot:
Kindly check with the above suggestion. Please get back us if you need further assistance.
Regards,
Berly B.C
KN
knilecrack
December 10, 2021 03:30 AM UTC
Hello Berly,
Appreciate the feedback, I'll give it a try tomorrow and I'll let you know.
BC
Berly Christopher
Syncfusion Team
December 10, 2021 06:45 AM UTC
Hi Knilecrack,
We will wait until hear from you.
Regards,
Berly B.C
KN
knilecrack
December 10, 2021 04:57 PM UTC
Hello Christopher,
Your approach does it. I thought I would get away without changing the culture, but I guess I will have to do it.
Thank you
Regards,
Milos
BC
Berly Christopher
Syncfusion Team
December 13, 2021 04:19 PM UTC
Hi Knilecrack,
Yes, we need to define the culture in the application when using the different format and culture.
Regards,
Berly B.C
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
KN knilecrack
- Dec 9, 2021 12:12 AM UTC
- Dec 13, 2021 04:19 PM UTC