osheh
osheh

Reputation: 105

Serialize and Deserialize Date between ASP.Net MVC and ExtJS

I've been searching through the web to look for a solution for this but still stuck.

I'm having difficulties serializing DateTime object. The standard serialize using DataContract will give this result /Date(1262600239000)/. After Ext.encode the result changed to /Date(1262600239000)/. The result from Ext.encode is not readable in ExtJS date related components such as DateField and ColumnModel for date.

As for deserializing, i'd have to provide the date in this /Date(1262600239000)/ format in order to deserialize the date. How can i achive this with the ExtJS DateField?

Is there any specific ways to get around this?

Thanks in advance.

Upvotes: 4

Views: 3091

Answers (2)

Mariano Desanze
Mariano Desanze

Reputation: 8163

You could try Newtonsoft Json.NET. It's open source and free (MIT license).

It is the one used by the Ext.Direct .NET Router which was developed by Evant (who is part of ExtJS Core Development Team).

You can see this code that uses it for a DateTime in the sample of Ext.Direct .NET Router:

[JsonObject]
public class Company {
    //...
    [JsonProperty(PropertyName = "started")]
    [JsonConverter(typeof(IsoDateTimeConverter))]
    public DateTime Started { get; set; }
    //...
}

Upvotes: 2

brianng
brianng

Reputation: 5820

Have you tried this?

It's an override for ExtJS' JSON encode and decode methods. Make sure to read the last comment as well.

Upvotes: 1

Related Questions