I am writing a sample GET method to return data from on-premise database. I serialize it first to a string so that the dates will be converted to ISO format. But when I deserialize it, it goes back to Microsoft format. I don't know what I am doing wrong
Any help is appreciated.
public class SalesOrderHeaderController : Controller
{
//
// GET: /SalesOrderHeader/
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult GetHeaders(string id)
{
var obj = DBHelpers.ExecuteQuery<SalesOrderHeader>(string.Format("select * from sales_order_hdr where sales_order_id = '{0}'", id));
JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.IsoDateFormat
};
string json = JsonConvert.SerializeObject(obj, microsoftDateFormatSettings);
ResponseObject res = new ResponseObject()
{
Code = "200",
Data = JsonConvert.DeserializeObject<List<SalesOrderHeader>>(json, microsoftDateFormatSettings)
};
return Json(res, JsonRequestBehavior.AllowGet);
}
}
class ResponseObject
{
public string Code { get; set; }
public object Data { get; set; }
}