1

I have this controller method that returns a JSON

public JsonResult InactiveUsers(int nbrOfInactiveDays)
{
  var results = FetchInactiveUsers(nbrOfInactiveDays);           
  return Json(results, JsonRequestBehavior.AllowGet);
}

the content of the result is a collection of object, where the object is defines like this

[DataContract]
public class Inactive
{
    [DataMember]
    public int UserID { get; set; }

    [DataMember]
    public string FullName { get; set; }

    [DataMember]
    public DateTime LastLoginDate { get; set; }
}

I already debugged to check the all the content and the LastLoginDate property and they all contains the date in this format {5/17/2014 12:43:55 AM}. But when I passed this back and do a console.log on the success call back of my ajax request the date of the first object is invalid

 $.ajax({
            type: "POST",
            url: "/User/InactiveUsers/",
            cache: false,
            traditional: true,
            dataType: "json",
            data: args,
            success: function (results) {
                console.log(results);

the content of the console.log shows that the LastLoginDate property of the first item is invalid

enter image description here

While the rest of the date is displayed as milli-seconds and is correct.

enter image description here

Just wondering what could have happened? The date time in millisecond is desirable because of the widget that I am using to display the data.

Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • Switch to JSON.Net serializer: http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx or write javascript code to parse that value into a valid date time object. – asawyer Jun 16 '14 at 18:04
  • possible duplicate of http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format – Ignacio Laborde Jun 16 '14 at 18:41
  • But why is it that the first date is not serialize correctly but the rest are? – Jack Thor Jun 16 '14 at 18:45

0 Answers0