0

i have table with these fields sms,id,updtd_date. im trying get it in json but date value getting in different format. how to get updt_time field in string in json

o/p

/Date(1497309538000)/

req op

13-06-2017 04:48

code

 public ActionResult getSMS()
        {
            using (DBEntities dc = new DBEntities())
            {
                var data = dc.sms.OrderByDescending(a => a.id).ToList();
                return Json(new { data = data }, JsonRequestBehavior.AllowGet);
            }
        }
3

1 Answer 1

0

You can serialize your date manually:

public ActionResult getSMS()
{
    using (DBEntities dc = new DBEntities())
    {
        var data = dc.sms.OrderByDescending(a => a.id);
        return Json(data.Select(d => new { d.sms, d.id, updtd_date = d.ToString("dd-MM-yyyy HH:mm") }).ToList(), JsonRequestBehavior.AllowGet);

    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

getting compilation error.list<sm> does not contain definition for sms, id. fields of tables are not coming.
@dotnetcoder sorry, my fault. Please check edited version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.