you would need to implement custom json converter.
public class invoiceConvertor : JavaScriptConverter
{
//private const string _dateFormat = "MM/dd/yyyy";
private const string _dateFormat = "yyyy-MM-dd";
public override IEnumerable<Type> SupportedTypes
{
get
{
return new[] { typeof(Invoice) };
}
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
//we are not using Deserialize for this example.
return new Object();
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
IDictionary<string, object> serialized = new Dictionary<string, object>();
var order = (Invoice)obj;
foreach (var prop in order.GetType().GetProperties())
{
if (prop.PropertyType == typeof(DateTime?))
{
DateTime? val = (DateTime?)prop.GetValue(order, null);
serialized[prop.Name] = (val == null) ? "" : ((DateTime)val).ToString(_dateFormat);
}
else
{
serialized[prop.Name] = prop.GetValue(order, null);
}
}
return serialized;
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
js.RegisterConverters(new[] { new invoiceConvertor() });