ASP.Net WebMethod fails because ko.toJSON() produces different results for DateTime.MinValue
Asked Answered
D

1

0

I'm getting an error when I call my WebMethod due to the Date format. I have a Date equal to DateTime.MinValue.

calling...

ko.toJSON({ employee: viewModel.employee });

[WebMethod]
public static string SaveEmployee(Employee employee)
{

}

I get the following results...

Chrome (works):
"terminationDate":"0001-01-01T06:00:00.000Z"

IE8 (does not work):
"terminationDate":"1-01-01T06:00:00Z"

How can I fix this?

Deafen answered 19/2, 2013 at 18:36 Comment(2)
#5943289Kunkle
I'd rather not add extra observables that don't map to the object on the server. This is my fix: JSON.parse(JSON.stringify(ko.toJSON({ employee: viewModel.employee })).replace(/\"1-01-01/g, "\"0001-01-01"));Deafen
D
0

I fixed it by padding the dates in my JSON:

var postData = JSON.parse(JSON.stringify(ko.toJSON(viewModel)).replace(/\"1-01-01/g, "\"0001-01-01"));
Deafen answered 22/2, 2013 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.